views:

252

answers:

3

Hi,

We need to redirect the user to a session timed out page whenever the ASP.Net session times out. We fetch most of our content through AJAX calls and the user never navigates away from the default page.
Is there any way to detect a session timeout on client side (in Javascript) without making any changes to the server-side code. Can we check the HTTP Status code?

Kind regards,

A: 

by default asp.net does not return a special status code when the session times out. You could detect this on the server side and set a specific status code if the session has timed out. You could also set a custom header or compose the content in a specific way when the session times out to inform code on the client side.

Matt Wrock
+1  A: 

You can just set a timer that is equal to the session timeout parameter on your server. If user is active the session will never timeout, if he closes the browser it will end automatically. So the only case you have is when the page is opened, but the user is not doing anything. In this case you can either keep the session alive for as long as you keep sending ajax requests (you can do this in background), or set a timer that indicates the time of inactivity.

HeavyWave
A: 

I Got Some Similar scenario and the following code solved my problem. //In Master Page: //180 is Session Timeout Time…. function SessionTimeOuts() { self.setTimeout("RedirectToLogin();", '180'); }

    function RedirectToLogin() {
        window.location.href = '../login.aspx';
    }

</script>

in Master Page Body tag Use onload= "SessionTimeOuts()"

santhosh