Javascript 如何使用ajax检查MVC会话是否过期?

Javascript 如何使用ajax检查MVC会话是否过期?,javascript,ajax,asp.net-mvc,Javascript,Ajax,Asp.net Mvc,我有适当的web.config设置,它可以正常工作,但只有当用户执行httpPost时,它才意识到应该重定向: <system.web> <sessionState mode="InProc" timeout="5" /> <compilation debug="true" targetFramework="4.5.1" /> <httpRuntime targetFramework="4.5.1" /> <authentication

我有适当的web.config设置,它可以正常工作,但只有当用户执行httpPost时,它才意识到应该重定向:

  <system.web>
<sessionState mode="InProc" timeout="5" />
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
<authentication mode="Forms">
  <forms loginUrl="~/Login/Login"></forms>
</authentication>

jqXHR.status在我的浏览器调试程序中返回undefined,我也尝试了props.status,但仍然未定义。有什么建议吗?

对超时会话的请求将导致http状态302(已找到),从而导致透明的重定向。因此jQuery不会自动处理这个问题。您可以让服务器返回http状态401(未经授权),而不是重定向。下面是一篇文章,其中包含可以复制的代码:

我正在使用401,并尝试使用文章中提到的xhr.status===401,但我仍然没有定义xhr.status。
var _redirectUrl = '@Url.Action("Logout", "Login")';
$(document).ajaxSuccess(function (event, request, settings, xhr, props, jqXHR) {
            if (jqXHR.status == 401) {
                window.location.href = _redirectUrl;
            }
        });