如何检查ajax调用会话是否过期?

时间:2013-10-01 12:48:36

标签: jquery asp.net ajax session session-timeout

我正在使用asp.net,并且在我的Web应用程序中为服务器的每个请求都有$ .ajax调用。

我想在会话结束时将用户重定向到“登录”页面。

在我的web.config中设置:

<authentication mode="Forms">
  <forms name=".CovertixAuthenticated" defaultUrl="Default.aspx" loginUrl="LoginPage.aspx" slidingExpiration="true" cookieless="UseCookies" protection="All" timeout="1"/>
</authentication>


  <sessionState mode="InProc" cookieless="UseCookies" timeout="1"/>

我签入了.ajaxError:

$(document).ajaxError(function(xhr, props) {
    if (props.status == 401) {
        var ParentUrl = encodeURIComponent(window.parent.location.href);
        //alert(getLoginPage());
        document.location.href = getLoginPage() + "?ReturnUrl=" + ParentUrl;
    }
});

问题是我得到responseCode = 500(内部服务器错误)

检查会话是否在ajax呼叫上过期的最佳方法是什么,或者如何在会话结束时自动将用户重定向到登录页面?

1 个答案:

答案 0 :(得分:0)

谢谢大家的帮助!

我忘了添加到我的web.config:

  <location path="MyPage.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>

现在我按预期得到了401!

相关问题