开发者

Session timeout and AJAX in ASP.NET

I have a button that executes a script using AJAX. Normally when a session is still active the script will return some data that will be placed inside the parent page. If the session expired the AJAX will return the login screen which gets placed inside the parent page which looks really odd.

How would I be able to detect a session timeout and d开发者_如何学编程o a postback on the parent page?


Since you are unlikely to be calling a full page, and you login page is likely to be a full page, you could just do the following.

if (xmlhttp.responseText.indexOf("DOCTYPE") != -1) {
    window.location.href = window.location.href;
}


When you make your call, first check to see if one of your session parameters is Nothing/null. If it is null, then your session has likely timed out. If you don't have any session variables that you explicitly set, you can set one when the user logs in.


What do you mean by 'if the session expired the AJAX will return the login screen'? You are in control of what is returned, so instead of returning the login screen return some sort of error code, or better throw an exception which you can catch as an error on the client.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜