【发布时间】:2016-11-29 11:39:21
【问题描述】:
我有一个带有此身份验证设置的 Asp.NET MVC 应用程序:
配置服务():
services.AddSession()
services.AddAuthentication(sharedOptions => sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
配置():
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
ClientId = "xx",
Authority = "xx",
Events = new OpenIdConnectEvents { OnRemoteFailure = this.OnAuthenticationFailed }
});
在 IIS 中托管时,某些用户会遇到此异常:
Microsoft.AspNetCore.Session.SessionMiddleware,
Error unprotecting the session cookie.
System.Security.Cryptography.CryptographicException: The key {9ec59def-874e-45df-9bac-d629f5716a04} 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)
我已经在托管服务器https://github.com/aspnet/DataProtection/blob/dev/Provision-AutoGenKeys.ps1上运行了这个
Web 仅具有 HTTPS 绑定,SSL 证书正常且已签名。什么可能导致这个问题?这个“关键”值究竟是什么?
【问题讨论】:
-
您是否在负载均衡器后面的多个实例中运行代码?此问题是否仅在应用程序重新启动之间发生?
-
@RubbleFord 没有负载均衡器,没有 webfarm。一台服务器,一台 IIS,一个服务所有请求的站点。
-
我也看到很多这样的:警告:Microsoft.AspNetCore.Session.DistributedSession[2] Accessing expired session, Key:67a44622-cea8-dd31-b0af-5b164cbec2ca
-
您解决了这个问题吗?我认为我遇到了类似的问题。
-
我的问题是我没有配置基于 Cookie 的 TempData 提供程序。见:docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state
标签: authentication iis asp.net-core