How to check if session expired on ajax call?

Inbal

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

I want to redirect the user to the Login page on session end.

In my web.config I set:

<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 in .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 I get responseCode = 500 (Internal server error)

What is the best way to check if session expired on ajax call, or how can I redirect the user to the login page automatically when session ends?

Inbal

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>

Now I get 401 as expected!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I check if my MVC session expired, using ajax?

How to check if the session is expired in Firebase

PHP session check not working in ajax call

How to check if a cookie is expired

How to check if date has expired

How to check a date is expired or not in Flutter?

How to check if the ajax call method is POST or GET?

How to detect expired user session in a react app?

How to identify if session has expired and current page

How to differentiate between logout and session expired?

How to detect if Azure Powershell session has expired?

How to redirect jsp page after session expired?

How to check if Session::has('loggedOn') and call a controller in a view?

check which user session is expired asp.net

Asp.net MVC - How to check session expire for Ajax request

How to call an AJAX function after setting a session variable?

Express Session not Working for Ajax Call

Yii ajax call and session handling

How to check if a date reached or expired for every year

InApp subscription expired, how to check it server side

How to check if access token is expired or not in android

How to check if a datefield is expired (Laravel/Lumen)

Mocha - how to check if element exist after ajax call

How to check if the ajax call for jQuery DataTable has returned data

How to check if a ResultSet of an AJAX call using JQuery has value

How can I check if an ajax .load call has loaded

How to check if a username is taken in Mongo Schema with an AJAX API call

How to check if a session is invalid

Check if AJAX call is success or not in codeigniter