【问题标题】:Asp.Net Core 1.1 The key was not found in the key ringAsp.Net Core 1.1 在密钥环中找不到密钥
【发布时间】:2017-11-20 00:02:38
【问题描述】:

DEFAULT PROJECT IN VS 2017 我在 vs 2017 社区中创建了一个新的 Asp.net Core Web 应用程序并将其发布在 FTP 主机上,但是当我提交表单(登录或创建用户)时出现此错误:

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

我需要做什么才能让它工作?谢谢。

【问题讨论】:

  • 您可能应该发布一些代码来显示什么不起作用。您的表单中有@Html.AntiForgeryToken() 吗?
  • 您应该查看 dataprotection api 的文档以了解密钥和密钥存储docs.microsoft.com/en-us/aspnet/core/security/data-protection/…
  • @MichaC it;'s the default project in VS 2017 点击问题主要部分的图片(DEFAULT PROJECT IN VS 2017)

标签: asp.net asp.net-core antiforgerytoken


【解决方案1】:

如果您的 IIS 应用程序池设置为使用 ApplicationPoolIdentity,那么您需要确保 IIS 应用程序池的“加载用户配置文件”设置为“真”。

见:https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/default-settings?view=aspnetcore-2.1

  1. 如果用户配置文件可用,密钥将保留在 %LOCALAPPDATA%\ASP.NET\DataProtection-Keys 文件夹中。如果操作 系统是 Windows,密钥使用 DPAPI 进行静态加密。

【讨论】:

    【解决方案2】:

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

    这是用于身份或登录 API 方面的。 当您的应用程序正在登录实例时。 并用另一个实例检查令牌。

    【讨论】:

    • 这并不能真正解决问题,也不适用于大规模部署。
    【解决方案3】:

    您的问题可能是您在 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.
    

    很可能会神奇地消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-26
      • 2022-06-26
      • 2017-10-08
      • 2020-07-15
      • 2022-01-24
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多