2021-03-29 乐帮网
iis log4net
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
提取码可以点击最下方按钮来查看。
关注我的微信公众号
在公众号里留言交流
投稿邮箱:1052839972@qq.com
庭院深深深几许?杨柳堆烟,帘幕无重数。
玉勒雕鞍游冶处,楼高不见章台路。
雨横风狂三月暮。门掩黄昏,无计留春住。
泪眼问花花不语,乱红飞过秋千去。
如果感觉对您有帮助
欢迎向作者提供捐赠
这将是创作的最大动力