繁体   English   中英

在 Redis 中具有分布式会话处理的 ASP.Net Core web-farm

[英]ASP.Net Core web-farm with distributed session handling in Redis

我正在尝试创建一个包含多个运行相同 ASP.NET Core 3.1 应用程序的 docker 容器的网络农场。 因此,我需要管理一个分布式会话,我的想法是使用 Redis 来做到这一点。

根据这篇文章,我在我的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";
});

当然,我从 Nuget 添加了两个包到我的应用程序:

  • Microsoft.AspNetCore.DataProtection.StackExchangeRedis
  • Microsoft.Extensions.Caching.StackExchangeRedis

不幸的是,分布式会话处理不起作用,我收到了一堆如下错误:

System.Security.Cryptography.CryptographicException:在密钥环中找不到密钥 {9b51134a-a57a-4129-9441-72859a985ab0}。

在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
在 Microsoft.AspNetCore.Session.CookieProtection.Unprotect(IDataProtector 保护器、字符串 protectedText、ILogger 记录器)

Microsoft.AspNetCore.Session.SessionMiddleware:警告:取消保护会话 cookie 时出错。

在 Redis 中,键“DataProtection-Keys”已创建但没有值。

如何使用 Redis 成功配置分布式会话/密钥管理?

此致...

其实我自己找到了答案。 我不得不从浏览器中删除所有现有的 localhost cookie。 在那之后,一切都奏效了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM