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

原文地址:https://www.cnblogs.com/ruiying/p/13164512.html