0
votes

I want my web page to close when SessionState timeout occures. This is my code in my web config:

<system.web>
<sessionState timeout="1" mode="InProc"/>
</system.web>

I set to 1 minute for testing purposes. The following is my Global.asax code:

protected void Session_End(object sender, EventArgs e)
{
    Response.Redirect("~/LogOut.aspx");
}

I put a label on one of the pages in order to check the session timeout, this is the code in the Page_Load event:

lblSession.Text = "SESSION TIME: " + Session.Timeout.ToString();

When I enter the site and come to this page the label shows SESSION TIME: 1, but after 1 minute I don't get redirected to the LogOut page and the present page is still fully active and working, apparently meaning that the session has not been terminated. I am working in Visual Studio 2008 thru the development server so suggestions I've seen relating to IIS settings don't seem to be relevant at this stage. Please help!

3

3 Answers

3
votes

HTTP is a request / response protocol. There is no persistent connection between the browser and the server. The code in Session_End thus effectively does nothing — it can't tell the browser to do anything.

You would need to make a (client-side) JavaScript timer and actively load the logout page right before the session timeout elapses.

1
votes

Session_End in my experience gets called on the first postback (could be implemented via a client-side Timer) after the timeout occurred - whenever that might be... if the user just closes the browser this event may never be called (except for the case you made a specific JS handler unload to do the postback in that situation).

For some information see:

0
votes

This doesn't seem to be the correct way of testing your session timeout. Try putting something in the session variables. Don't touch the page for another couple of minutes, and try reading it back from Session. If your session is alive, you should be able to see the variables, else... you won't.

Learn more about session and troubleshooting session... http://aspalliance.com/1182_Troubleshooting_Session_Related_Issues_in_ASPNET