Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset ASP.Net sessions state timeout with ajax request

I am working on an ASP.Net Full-Ajax site. Because all operations have doing by Ajax requests, any postback request will not send to server.In other hand I have a javascript timer that send an ajax request to check sessions and if it expired redirect user to login page.

Problem is here: When user is working on page for 20 minutes and all operations will do with ajax requests after 20 minutes its session expired and user will redirect to login page (by that javascript timer) exactly during working with page. So I need to refresh its session state with ajax request. But how ?How can I do that to reset sessions state timeout by an ajax request!?!!

Depend on my Google search results, I can not be preform by ajax request because SessionId store in client as a cookie and to update it need to preform a post back request :(

Note : Session state is set on InProc mode with timeout = 20

Sorry about my bad English syntax, I am new in English

Regards, Foroughi

UPDATE : Does an ajax request update sessions state timeout?!!

UPDATE : When my user login to site I set a session like this :

Session["UserId"] = UserObject.Id;

and in all my page I use some web method to preform operation like this :

[WebMethod]
public static Opr1 (Paramethers...)
{

   //Question is here , how can i update UserId  session to prevent to expire,how can i update it

   //execute my codes to preform Opr1

}
like image 673
Ali Foroughi Avatar asked Oct 09 '22 14:10

Ali Foroughi


1 Answers

If you are using WebMethods you should decorate your methods like

[WebMethod(EnableSession = true)]

Further if you need to keep your session alive you should try create an HTTPHandler that implements IRequireSessionState this interface allows to get/set(deserialize/serialize) the session variables that will eventually slide session timeout.

This is a good article about the sessions and ajax calls.

http://seejoelprogram.wordpress.com/2008/11/10/maintaining-aspnet-session-state-in-an-ajax-application/

Hope this will be helpful

Regards.

like image 199
Shoaib Shaikh Avatar answered Oct 12 '22 11:10

Shoaib Shaikh