ASP.Net Core 的Razor Pages项目部署在IIS中报错如下:
Category: Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery
EventId: 7
RequestId: 80000052-0007-fd00-b63f-84710c7967bb
RequestPath: /fman/Account
SpanId: |3ac22105-48985b027c2bcedd.
TraceId: 3ac22105-48985b027c2bcedd
ParentId: 
ActionId: 0ae135cd-857c-487b-86b6-69cca85ff66d
ActionName: /Account/Index

An exception was thrown while deserializing the token.

Exception: 
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.
 ---> System.Security.Cryptography.CryptographicException: The key {d2f4f529-e3fd-4bd2-8b59-1232ce77c285} was not found in the key ring.
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
   at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext)

在前端页面上看到的错误是:400 Bad Request。在Visual Studio中直接运行则没有问题,部署在Linux下也没有问题。里面涉及的问题太多了。这个错误是有关AntiForgeryToken的, 在这里提交一个解决问题的Demo。
在  Startup.cs 文件中的 public void ConfigureServices(IServiceCollection services)方法添加几行。

在IIS里部署ASP.NET Core Web程序可参考:https://lebang2020.cn/details/210322njnautk1.html

链接:https://pan.baidu.com/s/1WnmbEt6FV8MbasKgiT1lMg 
提取码可以点击最下方按钮来查看。

💰 此内容为付费阅读 请先登录