小编Kee*_*arn的帖子

反序列化令牌时抛出异常。无法在 .Net Core 2.2 应用程序中解密防伪令牌

我的日志中出现错误。我花了一天的大部分时间来寻找解决方案,但找不到满足我要求的解决方案。

这是日志错误

Severity=[ERROR], ipaddress=xxxx, subprocess=Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery, description=反序列化令牌时抛出异常。Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException:无法解密防伪令牌。---> System.Security.Cryptography.CryptographicException: 在密钥环中找不到密钥 {xxxxxxxxxx}。在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) ) 在 Microsoft.AspNetCore.DataProtection.KeyManagement。

    "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 …
Run Code Online (Sandbox Code Playgroud)

c# antiforgerytoken asp.net-core

10
推荐指数
1
解决办法
6690
查看次数

从 C# 中的字符串列表中删除前导和尾随空格

我有字符串列表,我想修剪前导和尾随空格。

它持有价值,如" Hi this "" computer "等等。

任何人都可以请建议我如何做到这一点?

List<string> aList = new List<string>();
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
639
查看次数

在 C# 中使用三元运算符

编写这行代码时出现错误。我想检查该值是否等于并大于0然后获取该值,否则获取空白或空值。

double h = model.WorkHours.Value>=0 ? model.WorkHours.Value:"";
Run Code Online (Sandbox Code Playgroud)

c# conditional-operator

-1
推荐指数
1
解决办法
107
查看次数