I've uploaded my website to a webhosting and this error came up;
'Error occurred during a cryptographic operation.'.

I've done some research and it seems that the formauthenticated cookie is bound to the MachineKey (which differs when using webhost).


I've found a method that should fix this problem but the error remains.

CODE:

/// <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();
        }
    }


STACKTRACE:

[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_Template\Archive_Template\Main.aspx.cs:481
   Archive_Template.Main.OnPreInit(EventArgs e) in f:\Archive_Template\Archive_Template\Main.aspx.cs:52
   System.Web.UI.Page.PerformPreInit() +31
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +335

推荐答案

对于任何没有解决问题的人来说,我的web.config中缺少加密/解密的"machineKey"条目

Asp.net相关问答推荐

Asp.Net Core 创建一个控制器来使用 SendGrid 发送邮箱

单个方法(即扩展方法)之间的调用不明确

在每个对象上设置 ClientIDMode = Static 是否有任何缺点(在母版页的 maincontent 上设置)

ASP .Net Web API 将图像下载为二进制

如何在 C# 中生成一个随机的 10 位数字?

Firefox 和 Chrome 之间 1 像素的行高差

如何在 ASP.NET WebForms 中实现 TDD

MSCharts找不到请求类型'GET'的http处理程序错误

如何将 Castle Windsor 与 ASP.Net Web 表单一起使用?

如何使用三个按钮是否和取消显示确认alert ,如 MS Word 中所示

如何更改 .ASPX 自动格式化设置 (Visual Studio)

如何配置 ASP.NET Core 1.0 以使用本地 IIS 而不是 IIS Express?

如何从 HTTP 请求中获取 MAC 地址?

如何在新实现的接口或基类之间做出决定?

Owin.IAppBuilder不包含MapSignalR的定义

错误请求 - 无效的主机名 ASP.net Visual Studio 2015

哪个控件导致了回发?

URL 路由、图像处理程序和潜在危险的 Request.Path 值

在 Visual Studio 2013 中更改项目端口号

在 ASP.NET 中写入文件以响应后回发不起作用