gpt4 book ai didi

asp.net-mvc - MVC 6 网络农场 : The antiforgery token could not be decrypted

转载 作者:行者123 更新时间:2023-12-04 14:42:25 28 4
gpt4 key购买 nike

我在 webfarm 场景(带有多个 AppServer 的 ARR 前端)中运行 MVC 6 (vNext)。服务器关联已关闭。
当我在应用服务器之间从一个请求跳到另一个请求时出现错误

CryptographicException: The key {3275ccad-973d-43ca-930f-fbac4d276640} was not found in the key ring.

InvalidOperationException: The antiforgery token could not be decrypted.


以前,我相信这是通过在 web.config 中设置静态 MachineKey 来处理的。
据我了解,我们现在已经转移到一个新的 DataProtection API,我尝试了以下操作,认为应用程序名称被用作某种种子:
        services.AddDataProtection();
services.ConfigureDataProtection(configure =>
{
configure.SetApplicationName("WebAppName");
});
这不能解决问题。
知道如何在 vNext 中解决这个问题吗?

最佳答案

解释

您需要重复使用相同的 key 。

如果您在 Azure 上, key 由 %HOME%\ASP.NET\DataProtection-Keys 上的 NAS 类型存储同步。 .

对于本地运行的应用程序,它们存储在 %LOCALAPPDATA%\ASP.NET\DataProtection-Keys 中。运行应用程序或存储在注册表中(如果它在 IIS 中执行)的用户的信息。

如果以上都不匹配,则为进程的生命周期生成 key 。

解决方案

所以第一个选项不可用(仅限 Azure)。但是,您可以同步来自 %LOCALAPPDATA%\ASP.NET\DataProtection-Keys 的 key 。在运行您的应用程序的每台机器上运行您的应用程序的用户。

但更好的是,您可以将其指向这样的网络共享:

sc.ConfigureDataProtection(configure =>
{
// persist keys to a specific directory
configure.PersistKeysToFileSystem(new DirectoryInfo(@"Z:\temp-keys\"));
});

这将允许您在保持安全性的同时进行扩展。

重要提示:您的 key 将每 90 天到期一次。经常再生它们很重要。

你可以使用这段代码来改变它,但越短,你就越安全。

services.ConfigureDataProtection(configure =>
{
// use 14-day lifetime instead of 90-day lifetime
configure.SetDefaultKeyLifetime(TimeSpan.FromDays(14));
});

来源
  • Key Encryption at Rest
  • Default Settings
  • 关于asp.net-mvc - MVC 6 网络农场 : The antiforgery token could not be decrypted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34319802/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com