加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

在解密Forms cookie时,c# – “加密操作期间发生错误”

发布时间:2020-12-14 21:25:25 所属栏目:资源 来源:网络整理
导读:我已经将我的网站上传到了webhosting,这个错误出现了。 ‘加密操作时发生错误’。 我已经做了一些研究,似乎已经认证的cookie被绑定到MachineKey(使用webhost时有所不同)。 我发现一个方法应该解决这个问题,但是错误仍然存??在。 码: /// summary /// Thi
我已经将我的网站上传到了webhosting,这个错误出现了。
‘加密操作时发生错误’。

我已经做了一些研究,似乎已经认证的cookie被绑定到MachineKey(使用webhost时有所不同)。

我发现一个方法应该解决这个问题,但是错误仍然存??在。

码:

/// <summary>
    /// This method removes a cookie if the machine key is different than the one that saved the cookie;
    /// </summary>
    protected void Application_Error(object sender,EventArgs e)
    {
        var error = Server.GetLastError();
        var cryptoEx = error as CryptographicException;
        if (cryptoEx != null)
        {
            FederatedAuthentication.WSFederationAuthenticationModule.SignOut();
            Global.Cookies.FormAuthenticated Cookie = new Global.Cookies.FormAuthenticated();
            Cookie.Delete();
            Server.ClearError();
        }
    }

堆栈跟踪:

[CryptographicException: Error occurred during a cryptographic operation.]
   System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func,Byte[] input) +115
   System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.Unprotect(Byte[] protectedData) +59
   System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket) +9824926
   Archive_Template.Main.resolveLoginUser(String sessionKey) in f:Archive_TemplateArchive_TemplateMain.aspx.cs:481
   Archive_Template.Main.OnPreInit(EventArgs e) in f:Archive_TemplateArchive_TemplateMain.aspx.cs:52
   System.Web.UI.Page.PerformPreInit() +31
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint) +335

解决方法

对于没有解决问题的人,我在我的web.config中缺少加密/解密的“machineKey”条目

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读