I'm trying to create a web-farm with multiple docker containers all running the same ASP.NET Core 3.1 app. Hence, I need to manage a distributed session and my idea was to use Redis to do that.
According to this article I added the following statements to my ConfigureServices
method:
var redis = ConnectionMultiplexer.Connect(redis_connection_string);services.AddDataProtection() .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys") .SetApplicationName("seminarmanager");services.AddStackExchangeRedisCache(o =>{ o.Configuration = redis_connection_string; o.InstanceName = "seminarmanager";});
Of course, I added two packages from Nuget to my app:
Microsoft.AspNetCore.DataProtection.StackExchangeRedis
Microsoft.Extensions.Caching.StackExchangeRedis
Unfortunately, distributed session handling does not work and I get a bunch of errors like the following:
System.Security.Cryptography.CryptographicException: The key {9b51134a-a57a-4129-9441-72859a985ab0} was not found in the key ring.
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
at Microsoft.AspNetCore.Session.CookieProtection.Unprotect(IDataProtector protector, String protectedText, ILogger logger)Microsoft.AspNetCore.Session.SessionMiddleware: Warning: Error unprotecting the session cookie.
In Redis the key "DataProtection-Keys" was created but has not value.
How can I successfully configure distributed session/key management with Redis?
Best regards...