Note that there are some explanatory texts on larger screens.

plurals
  1. POsession timeout on ajax call
    primarykey
    data
    text
    <p>I know this is duplicate but I could not get reliable solution(for asp.net web).</p> <p>I just want to redirect to the login page if session expires. I have tried following:</p> <h1>1. using jquery status code</h1> <pre><code> $.ajax({ type: "POST", url: "stream.asmx/SomeMethod", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { //success msg }, error: function (request, status, error) { if (status = 403) { location.href = 'login.aspx'; } } }); </code></pre> <p><strong>Problem:</strong> this returns same status code(403) for other errors too, which I only expect for session timeout.</p> <h1>2. Sending json message whether session expired</h1> <p>code behind:</p> <pre><code> if (!object.Equals(HttpContext.Current.Session["User"], null)) { Id = int.Parse(HttpContext.Current.Session["User"].ToString()); } else { result = from row in dtscrab.AsEnumerable() select new { redirectUrl = "login.aspx", isRedirect = true }; } </code></pre> <p>on $.ajax success:</p> <pre><code> success: function (msg) { if (msg.d[0].isRedirect) { window.location.href = msg.d[0].redirectUrl; } else { //load containt } } </code></pre> <p><strong>Problem:</strong> It's somehow desn't invoke ajax success line if session expires(it does return correct json). And even this is not a proper way if I have many number of ajax request in the page(should be handled globally). </p> <p>However, I saw this post which is really good soltion but it's for mvc using <code>AuthorizeAttribute</code>: <a href="https://stackoverflow.com/questions/5238854/handling-session-timeout-in-ajax-calls">handling-session-timeout-in-ajax-calls</a></p> <p><strong>So, Is there I can use same concept used in mvc using AuthorizeAttribute in asp.net web api? If not, how I can troubleshoot those issue which I'm facing (any of above two mentioned)?</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload