ASP.NET Core 2.1 Hangfire error on replication

10/21/2019

I using a kubernetes StatefulSet for a hangfire pod in gke kubernetes. It is working perfectly except when I make a replication. I get this exception due the Antiforgery token validation:

Microsoft.AspNetCore.Antiforgery.Internal.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 {9f4f1619-10ff-4283-a529-eb48a0799815} was not found in the key ring.

Is there any solution please ?

-- Mehdi Gasserini
asp.net-core
asp.net-core-2.0
hangfire
kubernetes

1 Answer

10/25/2019

The response is to Persist DataProtection key to redis

var redis = ConnectionMultiplexer.Connect("localhost,password=password");

services.AddDataProtection()
        .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
-- Mehdi Gasserini
Source: StackOverflow