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相关问答推荐

Razor页面上@Foreach的正确语法,其中值可以等于多个值

使用进程外会话状态的 ASP.NET 应用程序中的 SQL Server 连接问题

将 Global.asax 迁移到 Startup.cs

是否可以访问位于另一个项目中的 MVC 视图?

使用 jQuery 验证插件匹配两个字段

为什么 Asp.Net Identity IdentityDbContext 是一个黑盒?

通过 jQuery 调用 ASP.NET 服务器端方法

从 C# AsyncCTP 使用 ExecuteReaderAsync 的任何缺点

IIS 10 上的 ASP.NET Core 404 错误

在 ASP.NET 中实现 404 的最佳方法

解析器错误消息:无法加载类型网络营销

Web API 必填参数

调查 Web.Config 重复部分原因的步骤

使用 ASP.NET 进行重定向后获取

如何遍历自定义 vb.net 对象的每个属性?

ASP.NET MVC 和 httpRuntime executionTimeout

使用 NLog 在 ASP.NET Web API 2.1 中进行全局异常处理?

IsMobileDevice 是如何工作的?

Page.IsPostBack 和 Page.IsCallBack 有什么区别?

System.Drawing.Image.FromFile() 上的内存不足异常