开发者

ASP.NET session expires in Ajax request

There are a lot of questions already made here about what to do when session expires when doing an Ajax request. One of the workarounds 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 requests, that makes that the session expires in the determined time, but is there the possibility to update the session timout in the Ajax r开发者_StackOverflow中文版equests (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?


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 issuing Ajax requests. It might be that they only are kept alive, when the corresponding WebService has the EnableSession attribute set. You can try that too.

For example,

[WebMethod( EnableSession = true )]
public string WebServiceMethod(){ return "I'm session aware.";}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜