Which is the easiest and most unobstrusive way to keep an ASP.NET session alive as long as the user has the browser window open? Is it timed AJAX calls? I want to prevent the following: sometimes users keep their window open for a long time, then enter stuff, and on submit nothing works anymore because the server side session expired. I don’t want to increase the timeout value for more than 10 min on the server as I want closed sessions (by closing the browser window) to time out fast.
Suggestions, code samples?
I use JQuery to perform a simple AJAX call to a dummy HTTP Handler that does nothing but keeping my Session alive:
Session handler can be as simple as:
The key is to add IRequiresSessionState, otherwise Session won’t be available (= null). The handler can of course also return a JSON serialized object if some data should be returned to the calling JavaScript.
Made available through web.config:
added from balexandre on August 14th, 2012
I liked so much of this example, that I want to improve with the HTML/CSS and the beat part
change this
into
and add
HTML and CSS
here is a live example for only the beating part: http://jsbin.com/ibagob/1/