Asp.Net Core 1.1密钥环中找不到该密钥

15

VS 2017中的默认项目

我在VS 2017 Community中创建了一个新的Asp.net Core Web应用程序并将其发布到FTP托管,但当我提交表单(登录或用户创建)时,出现以下错误:

Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery[7] 在反序列化令牌时引发了异常。 System.InvalidOperationException:解密防伪令牌失败。-->System.Security.Cryptography.CryptographicException: 密钥{...}在密钥环中未找到。

我需要做什么才能使它正常工作?谢谢。


你可能需要发布一些代码来展示哪里出了问题。你的表单中是否有 @Html.AntiForgeryToken() - MichaC
你应该查看Dataprotection API的文档,以了解有关密钥和密钥存储的信息。https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/introduction - Joe Audette
@MichaC 这是VS 2017中的默认项目,请单击问题主部分中的图像(VS 2017中的默认项目)。 - Dragos Niamtu
3个回答

15

6
很可能你的问题是因为在IIS中禁用了用户配置文件。 应用程序池,更新它后错误就会消失。
[WRN] Error unprotecting the session cookie.
System.Security.Cryptography.CryptographicException: The key {e47d051f-d492-4df7-8781-31d884833ec6} was not found in the key ring.

以及防伪

[ERR] 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 {e47d051f-d492-4df7-8781-31d884833ec6} was not found in the key ring.

很可能会神奇地消失。


-3

如果您的托管环境为应用程序使用多个实例,则可能是问题的原因。 解决此问题的最简单方法是缩减到一个实例,并将最大实例数设置为1。

这适用于身份验证或登录API方面。 因为您的应用程序正在登录到一个实例。 并检查另一个实例的令牌。


3
这并没有真正解决问题,也不适用于大规模部署。 - Stuart Frankish

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接