我已经将我的网站上传到网站主办,这个错误出现了;
' 在加密操作期间发生错误.'.
我做了一些研究,似乎将经过形式化的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();
}
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
[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) …Run Code Online (Sandbox Code Playgroud) 当我尝试在ASP.NET MVC应用程序上获取主页时,我遇到了这个异常.
[CryptographicException:加密操作期间发生错误.]
System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func,Byte [] input)+246
System.IdentityModel.Services.MachineKeyTransform.Decode(Byte [] encoded) +191
System.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte [] cookie,Boolean outbound)
+173 System.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader,SecurityTokenResolver tokenResolver)+756
System.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken( Byte [] token,SecurityTokenResolver tokenResolver)+100
System.IdentityModel.Services.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte [] sessionCookie)+1164
System.IdentityModel.Services.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken&sessionToken)+287
System.IdentityModel.Services.SessionAuthenticationModule. OnAuthenticateRequest(Object sender,EventArgs eventArgs)+231
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+80 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean&completedSynchronously)+165
据我所知,SessionAuthenticationModule的cookie出了问题.如果您清除cookie(如此处已在Azure上联合身份验证中所述),它可以正常工作.我想要的是了解发生了什么,如何捕捉异常并解决问题.
我收到以下错误.这似乎只是在我升级我的visual studio 2015以进行第一次更新后才开始.我在这里读过一些关于机器密钥问题的线程吗?我不知道如何解决它并防止它.目前,当我使用IIS express在调试中运行时,我在本地计算机上收到此错误.
Exception Details: System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.
Cache = db.UserTokenCacheList.FirstOrDefault(c => c.webUserUniqueId == userId);
// place the entry in memory
this.Deserialize((Cache == null) ? null : MachineKey.Unprotect(Cache.cacheBits,"ADALCache"));
[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) +70
System.Web.Security.MachineKey.Unprotect(ICryptoServiceProvider cryptoServiceProvider, Byte[] protectedData, String[] purposes) +62
System.Web.Security.MachineKey.Unprotect(Byte[] protectedData, String[] purposes) +121
LEDES.Models.ADALTokenCache..ctor(String signedInUserId) in C:\Users\RLewis\Source\Workspaces\Workspace\LEDES\LEDES\Models\AdalTokenCache.cs:28
LEDES.Startup.<ConfigureAuth>b__7_0(AuthorizationCodeReceivedNotification context) in C:\Users\RLewis\Source\Workspaces\Workspace\LEDES\LEDES\App_Start\Startup.Auth.cs:54
Microsoft.Owin.Security.OpenIdConnect.<AuthenticateCoreAsync>d__1a.MoveNext() +4388
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +26
Microsoft.Owin.Security.OpenIdConnect.<AuthenticateCoreAsync>d__1a.MoveNext() +5776
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 …Run Code Online (Sandbox Code Playgroud) 根据文档,这两个模块都将用于创建IClaimsPrincipal的实例.我不明白为什么WIF懒得使用2个HttpModules而不是一个?对不起,我是WIF新手