联合身份验证和"加密操作期间发生错误"

Dav*_*ave 19 .net asp.net federated-identity

当我尝试在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上联合身份验证中所述),它可以正常工作.我想要的是了解发生了什么,如何捕捉异常并解决问题.

eXa*_*ier 16

发布时,cookie包含使用当前machineKey加密的安全令牌.当前一个版本的cookie被发送回服务器时,SAM(更准确地说是令牌处理程序)尝试使用machineKey的新值来解密它,这会导致错误.在相关帖子(Azure上的联合身份验证)中检查我的答案以缓解错误.HTH