zoukankan      html  css  js  c++  java
  • Error unprotecting the session cookie.The payload was invalid.

     .Net Core 3.0

    warn: Microsoft.AspNetCore.Session.SessionMiddleware[7]
          Error unprotecting the session cookie.
    System.Security.Cryptography.CryptographicException: The payload was invalid.
       at Microsoft.AspNetCore.DataProtection.Cng.CbcAuthenticatedEncryptor.DecryptImpl(Byte* pbCiphertext, UInt32 cbCiphertext, Byte* pbAdditionalAuthenticatedData, UInt32 cbAdditionalAuthenticatedData)
       at Microsoft.AspNetCore.DataProtection.Cng.Internal.CngAuthenticatedEncryptorBase.Decrypt(ArraySegment`1 ciphertext, ArraySegment`1 additionalAuthenticatedData)
       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.Session.CookieProtection.Unprotect(IDataProtector protector, String protectedText, ILogger logger)

    漏加了 services.AddDataProtection()

    public void ConfigureServices(IServiceCollection services)
    {
    
        services.AddSession(); 
        services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "DataProtection"));
        
        services.AddRazorPages().AddRazorRuntimeCompilation();
        services.AddControllersWithViews(); 
    }
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    { 
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseStatusCodePagesWithReExecute("/Home/Error");
        }
    
        app.UseSession(); 
    }

  • 相关阅读:
    MySQL Connector Net 6.6.5 Entity Framework 显式预加载 Eager Load Bug
    MySQL 5.6 Replication 复制 FAQ
    MySQL 实现 EF Code First TimeStamp/RowVersion 并发控制
    Linux 系统命令备忘
    MySQL 自增列插入0值的方法
    【转载】将数据存储到SmartObject中
    【转载】使用C#代码发起K2 Blackpearl流程
    【转载】WorkFlow、BPM、SOA
    百度统计喻友平:谈如何更好的优化网站质量
    【转载】浅识K2 blackpearl中SmartObject
  • 原文地址:https://www.cnblogs.com/vipsoft/p/13045581.html
Copyright © 2011-2022 走看看