The antiforgery token could not be decrypted.


.net core 3.1 在Linux上发布的时候遇到如下问题:

Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery[7]

An exception was thrown while deserializing the token.
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.

 

是因为 .net croe 的coookie的生成验证要使用MecachineKey找不到,或者分布式部署时两个程序读取的Meachine Key不一致造成的,
这个时候需要我们设置同一个MeacheineKey

参考文章

https://docs.microsoft.com/zh-cn/aspnet/core/security/data-protection/implementation/key-storage-providers?view=aspnetcore-3.1&tabs=visual-studio
https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.dataprotection.stackexchangeredisdataprotectionbuilderextensions.persistkeystostackexchangeredis?view=aspnetcore-3.0

找了一些文章,最后找到了解决方法:

https://www.cnblogs.com/ruiying/p/13164484.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM