简体   繁体   English

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

[英]XSRF token expired after website publish to IIS

I am using ASP.NET Boilerplate framework, I put the below code in everypage. 我正在使用ASP.NET Boilerplate框架,在每个页面中都放置了以下代码。

@inject IAbpAntiForgeryManager AbpAntiForgeryManager

@{
    AbpAntiForgeryManager.SetCookie(Context);
}

I call the app service as below: 我将应用程序服务称为:

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

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

Everything works fine when I run in localhost, XSRF token will not expired even if I rebuild the project. 当我在localhost中运行时,一切正常,即使重建项目,XSRF令牌也不会过期。 Every time when I click [Publish website to IIS], all the ajax request will return 400 Bad Request, I guess it is because the XSRF token has expired, everything back to normal after I click F5 in browser. 每次单击[将网站发布到IIS]时,所有的ajax请求都将返回400 Bad Request,我猜这是因为XSRF令牌已过期,在浏览器中单击F5之后,一切恢复了正常。 It was so annoying for the user, any thing I can do to prevent this error? 这对用户来说太烦人了,我能做些什么来防止此错误? Or auto refresh token? 还是自动刷新令牌?

Thank you! 谢谢!

update 更新

error message in LOG file: 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.

Based on the error it sounds like your Data Protection keys have rotated on publish. 根据错误,听起来您的数据保护密钥在发布时已经旋转。 Check out the docs on Data Protection here: https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/introduction?view=aspnetcore-2.2 . 在此处查看有关数据保护的文档: https : //docs.microsoft.com/zh-cn/aspnet/core/security/data-protection/introduction?view=aspnetcore-2.2 There's a bunch of options how to configure it, where to store keys etc. You'll want to change how it is storing them. 有很多选项如何配置它,在哪里存储密钥等。您将需要更改它存储它们的方式。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM