我有一个网站是我们基于WIF的自定义STS的依赖方。我们最近实现了一个安全令牌缓存,如下所述:Azure/web-farm ready SecurityTokenCache。我们的实现和该链接中描述的实现之间的主要区别在于,我们使用Azure AppFabric缓存作为持久缓存的后备存储,而不是表存储。这有助于缓解我们在某些浏览器上出现令牌截断问题,但却引入了一个新问题(我们看到截断问题主要出现在除了fedauth cookie之外还包含Google Analytics(分析)+ antiforgery cookie的页面上)。我们现在会收到以下异常数千次,每天:WIF安全令牌缓存
System.IdentityModel.Tokens.SecurityTokenException
ID4243: Could not create a SecurityToken. A token was not found in the token cache and no cookie was found in the context.
System.IdentityModel.Tokens.SecurityTokenException: ID4243: Could not create a SecurityToken. A token was not found in the token cache and no cookie was found in the context.
at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver)
at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver)
at Microsoft.IdentityModel.Web.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie)
at Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken)
at Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
此异常似乎重定向循环要发生的事情,所以我们一个1-2分钟的时间跨度内看到数百人。
在研究异常时,我一直无法找到任何有用的信息。迄今为止唯一的希望是有人提到它可能与会话之前到期的缓存对象有关。
我们无法在内部重现问题,只知道它存在是因为成千上万的条目填满了我们的Elmah表。任何帮助或见解将非常感激。
我们推出了我们认为可能有助于解决这个问题(下面的代码),但它没有任何效果:
HttpContext.Current.Response.Cookies.Remove("FedAuth");
WSFederationAuthenticationModule authModule = FederatedAuthentication.WSFederationAuthenticationModule;
string signoutUrl = (WSFederationAuthenticationModule.GetFederationPassiveSignOutUrl(authModule.Issuer, authModule.Realm, null));
Response.Redirect(signoutUrl);
我们所实现的安全令牌缓存,因为我们的cookies的集体栈是超过某些浏览器(Safari浏览器,Opera等)的4096个字节的域cookie大小限制。它是为了响应cookie截断问题而实现的。我们也已经使用基于证书的cookie加密。安全令牌缓存对我们来说是“必须的”,并且具有我们希望的效果,但是实现已经创建了这个新的例外。这个异常的真正问题是它将我们的用户引入重定向循环。 – Jeff 2012-03-28 15:59:09