.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
找了一些文章,最后找到了解決方法: