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