How would you deal with this problem? Jquery + ajax + server timeout

I am using asp.net mvc, c # and jquery. My site uses ajax heavily. This led to a problem, and I'm not sure how to fix it (better to fix it than my current solution).

Scenario.

  • A user enters my site - a set of cookies, the server has a timeout of 30 minutes
  • User leaves within 30 minutes
  • User comes back and clicks on one jquery tab with ajax enabled
  • Request sent to server
  • The server did not shut down by sending them back to the subscription page.
  • since this is an ajax request, the redirect receives the render in the tab. It looks ugly (the whole page displayed on the tab), the user is probably very confused at this point.

Problem

  • As for the server and ajax, the ajax request is valid and the success response is sent back. Therefore, I cannot check the error, because the request was successful, and not the correct data returned.

Solution 1

  • The user is logged in.
  • Jquery ajax request made to find out user timeout
  • 60 seconds less than server timeout
  • Once the time runs out on the javascript side. A jQuery dialog box appears and tell them that their session has expired and forces them to redirect to enter the package.
    • The user cannot click on anything, as a dialog box blocks it. If some firebug users or something they can delete, but then the server timeout will still work, and they will get the ugly version (then it does not bother).
  • ajax, - reset, , .

  • , , - , 45 reset . .

  • , ( ), , . (, , ). , - , - .

, 2 , .

2 ().

, , - , , 303 - , , jquery .

, #, - .

+3
3

HTTP- LogOn, AJAX :

public ActionResult LogOn()
{
    Response.AddHeader("X-LOGON", "LogOn");
    return View();
}

:

$.ajax({
    url: '/home/someaction',
    success: function (data, textStatus, XMLHttpRequest) {
        if (XMLHttpRequest.getResponseHeader('X-LOGON') === 'LogOn') {
            // the LogOn page is being displayed 
            // probably timeout or unaithorized => act accordingly
        }
    }
});
+3

, ( ) , 403 (), AJAX , window.location /login.

+2

1, , (1) (2) , . , http://farm-fresh-code.blogspot.com, . , , , .

+2

Source: https://habr.com/ru/post/1751087/


All Articles