views:

22

answers:

2

Hi.

There are a lot of questions already made here about what to do when session expires when doing a Ajax request. One of the workaround is place a header in the response that makes a redirection to the login page.

My site only does the first page postback, then it's all ajax request, that makes that the session expires in the determined time, but what i want to know is if there is the possibility to update the session timout in the Ajax request's (in the asp handler that attends the request), so that the session does expire but only when i passed the timeout time without make any request to the server at all.

Thanks.

+1  A: 

You could implement a KeepAlive SessionObserver (javascript) and track Session Timeouts yourself. That way you can trap SessionTimeouts of idle users, redirect them with a message and other useful things.

Apart from that, Sessions should be kept alive when issueing Ajax Requests. Might be that they only are kept alive, when the corresponding WebService has the EnableSession attribute set. You can try that too.

eg

[WebMethod( EnableSession = true )]
public string WebServiceMethod(){ return "i'm session aware";}
ovm
+1  A: 

I am not sure if I understand your question correctly. You said, "update the session timeout in AJAX request". Normally, you don't need to do it explicitly. Even though the request is an AJAX request, the Page Life Cycle doesn't change a bit. The modules/handlers will work the same way as they should. Hence, your session related information will automatically get updated.

Rahul Soni
Ok, just like ovm have said, Session should been kept alive by the Ajax request. I thought that when doing the request, a server request will be made but the page life cycle won't occur. Thanks
Ruben F.
My pleasure. Please mark the response as answer if you think it is :)
Rahul Soni