How to check if a session ended when calling ajax?

I am using asp.net and I have $ .ajax calls in my web application for every server request.

I want to redirect the user to the login page at the end of the session.

In my web.config, I installed:

<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"/>

and I check .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;
    }
});

The problem is that I get responseCode = 500 (internal server error)

What is the best way to check if a session has ended when ajax is called, or how can I redirect the user to the login page automatically when the session ends?

+4
source share
1 answer

Thanks guys for the help!

I just forgot to add to my web.config:

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

401, !

0

All Articles