如何避免’SamlAssertion.NotOnOrAfter条件不满意’错误

最近,我开始在现有的Web应用程序上使用基于声明的身份validation。 因为应用程序使用jQuery,尤其是AJAX函数,我不得不改变处理程序,不要尝试重定向XmlHTTPRequests ,而是返回403状态,这更容易处理。

这是FederatedAuthentication.WSFederationAuthenticationModule.AuthorizationFailed事件hanlder:

  protected void WSFederationAuthenticationModule_AuthorizationFailed(object sender, AuthorizationFailedEventArgs e) { //WSFederationAuthenticationModule sam = (WSFederationAuthenticationModule)sender; HttpContext context = HttpContext.Current; HttpRequest req = context.Request; HttpResponse resp = context.Response; if (req == null || resp == null) return; if ((resp.StatusCode == 302 || resp.StatusCode == 401) && req.Headers["X-Requested-With"] == "XMLHttpRequest") { resp.StatusCode = 403; e.RedirectToIdentityProvider = false; } } 

我有以下模式实现AJAX调用并处理响应:

 $.ajax({ cache: false, data: $.param(o), dataType: "xml", url: "AJAXCall.ashx", success: function (data) { // Success handler }, error: function (XMLHttpRequest, textStatus, responseText) { if (XMLHttpRequest.status == 403) { var retVal = window.showModalDialog("Session.aspx", "", "dialogHeight: 250px; dialogWidth: 250px; edge: Raised; center: Yes; resizable: Yes; status: Yes;"); if (retVal) { // Succesful session renewal handler } else { // Session renewal failure handler } } else { // Other errors handler } } }); 

如果成功地重定向到身份提供程序并返回,则“Session.aspx”基本上会关闭模式对话框,其返回值为true。

但我的问题是我收到以下错误:

“ID4223:SamlSecurityToken被拒绝,因为不满足SamlAssertion.NotOnOrAfter条件。”

这是在模拟当前应用程序用户的子系统上调用的,显然前一个会话的标记仍然存在。 我在我的应用程序的web.config中有以下设置:

    

如何避免此错误? 任何帮助将不胜感激。

以下FederatedAuthentication.WSFederationAuthenticationModule.SignInError事件处理程序方法解决了问题:

  protected void WSFederationAuthenticationModule_SignInError(object sender, ErrorEventArgs e) { // handle an intermittent error that most often occurs if you are redirected to the STS after a session expired, // and the user clicks back on the browser - second error very uncommon but this should fix if (e.Exception.Message.StartsWith("ID4148") || e.Exception.Message.StartsWith("ID4243") || e.Exception.Message.StartsWith("ID4223")) { FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie(); e.Cancel = true; } } 

即使用户在会话过期后被重定向到STS服务,它也会删除持久存在的会话令牌Cookie。