asp.net - 网站发布到 IIS 后 XSRF 令牌过期
问题描述
我正在使用 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请求都会返回400 Bad Request,我猜是因为XSRF令牌已经过期,在浏览器中点击F5后一切恢复正常。这对用户来说太烦人了,我能做些什么来防止这个错误?还是自动刷新令牌?
谢谢!
更新
LOG 文件中的错误消息:
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 。
推荐阅读
- sql - 如何使用另外两个表的选择内连接的结果更新第三个表
- python - 通过使用 np.newaxis 进行 RGB 成像,从 (:,:,1) 扩展到 (:,:,3)
- reporting-services - 在 ssrs 报告中,如果地址字段有一个空值,它会生成一个空白空间
- java - 遍历并仅获取文件名?
- laravel - 在不同文件夹中使用单个命令创建模型、控制器和迁移
- python - 提取列值并将其存储在数组中
- c# - 如何测试这种异步删除方法?
- javascript - 无法从数组 ES6 中获取信息
- html - 圆形通知在不同的容器中变成 30 像素宽的药丸
- python - Heroku docker 镜像需要一个开放的端口