<p>I am making use of a Redis database for Data Protection on .net core 3.0 on Kubernetes, but still get the below error. Any ideas?</p>

<blockquote>
  <p>fail: Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery[7]
        An exception was thrown while deserializing the token. Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The
  antiforgery token could not be decrypted.  --->
  System.Security.Cryptography.CryptographicException: The key
  {ffb146a1-0e5e-4f96-8566-425f7c2eb99a} was not found in the key ring. 
  at
  Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[]
  protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus&amp;
  status)    at
  Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[]
  protectedData, Boolean ignoreRevocationErrors, Boolean&amp;
  requiresMigration, Boolean&amp; wasRevoked)    at
  Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[]
  protectedData)    at
  Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String
  serializedToken)    --- End of inner exception stack trace ---    at
  Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String
  serializedToken)    at
  Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext
  httpContext)</p>
</blockquote>

<pre><code>var redis = ConnectionMultiplexer.Connect(Environment.GetEnvironmentVariable("REDIS_CONNSTR"));
services.AddDataProtection().PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
services.AddMvc(options =&gt;
{
    options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
</code></pre>

<p>According to the documentation in the below article the application name needs to be set.</p>

<pre><code>services.AddDataProtection()
    .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys")
    .SetApplicationName("product");
</code></pre>

<blockquote>
  <p>By default, the Data Protection system isolates apps from one another
  based on their content root paths, even if they're sharing the same
  physical key repository. This prevents the apps from understanding
  each other's protected payloads.</p>
  
  <p>To share protected payloads among apps:</p>
  
  <ul>
  <li>Configure SetApplicationName in each app with the same value.</li>
  </ul>
</blockquote>

<p><a href="https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-3.0" rel="noreferrer">https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-3.0</a></p>

<p>Just a further note on this. If you get a 400 Bad Request and are using an API in the same solution then I would suggest having a look at the IgnoreAntiforgeryToken Attribute to decorate methods where CSRF does not apply.</p>

<pre><code>[HttpPost]
[IgnoreAntiforgeryToken]
</code></pre>
