XSRF 令牌在网站发布到 IIS 后过期

XSRF token expired after website publish to IIS

我正在使用 ASP.NET 样板框架,我将以下代码放在每个页面中。

@inject IAbpAntiForgeryManager AbpAntiForgeryManager

@{
    AbpAntiForgeryManager.SetCookie(Context);
}

我调用应用服务如下:

var xhr = abp.services.app.order.add(data);

        xhr.done(function (data) {
            alert(data);
        });

当我在 localhost 中 运行 时一切正常,即使我重建项目,XSRF 令牌也不会过期。每次点击[Publish website to IIS],所有ajax request都会return 400 Bad Request,我猜是因为XSRF token过期了,点击F5后一切正常浏览器。这对用户来说太烦人了,我能做些什么来防止这个错误?还是自动刷新令牌?

谢谢!

更新

日志文件中的错误消息:

ERROR 2019-02-12 13:40:09,773 [71   ] .Antiforgery.Internal.DefaultAntiforgery - 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 {996d31d2-0fa3-4ffe-8e82-e155c1486d33} was not found in the key ring.

根据错误,您的数据保护密钥似乎已在发布时轮换。 在此处查看有关数据保护的文档:https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/introduction?view=aspnetcore-2.2。 有很多选项如何配置它,在哪里存储密钥等。 您需要更改其存储方式。

有关配置数据保护的更多信息:https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-2.2