[英]ASP.Net Core web-farm with distributed session handling in Redis
I'm trying to create a web-farm with multiple docker containers all running the same ASP.NET Core 3.1 app.我正在尝试创建一个包含多个运行相同 ASP.NET Core 3.1 应用程序的 docker 容器的网络农场。 Hence, I need to manage a distributed session and my idea was to use Redis to do that.因此,我需要管理一个分布式会话,我的想法是使用 Redis 来做到这一点。
According to this article I added the following statements to my ConfigureServices
method:根据这篇文章,我在我的ConfigureServices
方法中添加了以下语句:
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:当然,我从 Nuget 添加了两个包到我的应用程序:
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. System.Security.Cryptography.CryptographicException:在密钥环中找不到密钥 {9b51134a-a57a-4129-9441-72859a985ab0}。
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)在 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)在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
at Microsoft.AspNetCore.Session.CookieProtection.Unprotect(IDataProtector protector, String protectedText, ILogger logger)在 Microsoft.AspNetCore.Session.CookieProtection.Unprotect(IDataProtector 保护器、字符串 protectedText、ILogger 记录器)Microsoft.AspNetCore.Session.SessionMiddleware: Warning: Error unprotecting the session cookie. Microsoft.AspNetCore.Session.SessionMiddleware:警告:取消保护会话 cookie 时出错。
In Redis the key "DataProtection-Keys" was created but has not value.在 Redis 中,键“DataProtection-Keys”已创建但没有值。
How can I successfully configure distributed session/key management with Redis?如何使用 Redis 成功配置分布式会话/密钥管理?
Best regards...此致...
I actually found an answer by myself.其实我自己找到了答案。 I had to delete all existing localhost cookies from my browser.我不得不从浏览器中删除所有现有的 localhost cookie。 After that, everything worked.在那之后,一切都奏效了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.