【发布时间】:2020-12-06 04:36:50
【问题描述】:
我的日志中出现错误。我花了大部分时间寻找解决方案,但找不到符合我要求的解决方案。
这是日志错误
严重性=[错误],ipaddress=xxxx, 子进程=Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery, 描述=反序列化令牌时引发异常。 Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: 防伪令牌无法解密。 ---> System.Security.Cryptography.CryptographicException:密钥 未在密钥环中找到 {xxxxxxxxx}。在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(字节[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& 状态)在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(字节[] protectedData,布尔型 ignoreRevocationErrors,布尔型& requiresMigration, Boolean& wasRevoked) 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(字节[] 受保护数据)在 Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgeryTokenSerializer.Deserialize(字符串 序列化令牌)在 Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgeryTokenSerializer.Deserialize(字符串 序列化令牌)在 Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext)
"Certificates": {
"StoreName": "My",
"StoreLocation": "LocalMachine"
"SerialNumber": "xxxxxxxxxxxx"
},
private X509Certificate2 LCertificate()
{
var storeName = Configuration["Certificates:StoreName"];
var storeLocation = Configuration["Certificates:StoreLocation"];
string serialNumber = Configuration["Certificates: SerialNumber"];
using(X509Store store = new X509Store(storeName,storeLocation))
{
var certificates = store.Certificates
.Find(X509FindType.FindBySerialNumber,
serialNumber,
acceptValidCertOnly);
return certificates[0];
}
}
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer
.AddSigningCredential(new X509Certificate2(LCertificate()))
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginModel model)
{
【问题讨论】:
标签: c# asp.net-core antiforgerytoken