views:

82

answers:

3
<script language="javascript" type="text/javascript">
    setTimeout('SessionTimeout()', <%= Session.Timeout * 60 * 1000 %>);
    function SessionTimeout() {
        alert(<%= "'Session time out!!'" %>);
        window.location = "Default.aspx"
    }
</script>

Does the above code will help in session time out ? If so how many minutes? how i can increase it to 19 minutes ?

Please help !!

+2  A: 

In ASP.NET the Session.Timeout defaults to 20 minutes. In your example above the SessionTimeout() javascript function should be called after 20 minutes on the same page. You can configure the Session Timeout using the web.config file.

For information on editing the web.config check refer to MSDN

Kane
there is no entry in my webconfig file for session ..but still the session is timing out after some time.. do i need to edit the web.config if so ..how ?
To update the web.config sessionState element check out MSDN: http://msdn.microsoft.com/en-us/library/h6bb9cz9%28VS.71%29.aspx
Kane
+1  A: 

Session timout is set in the web server (IIS) settings for your website. Here are instructions for IIS 7.

What your code does will reset the timeout, but only if the page refreshes before the timeout actually occures.

You are redirecting to your default.aspx just after the timeout has occured, not before.

Oded
+1  A: 

To set the timeout to 19 minutes, use:

setTimeout(SessionTimeout, 19 * 60 * 1000);

Or you can use 1140000 (the number of milliseconds in 19 minutes) instead of 19 * 60 * 1000 - but the latter makes it clearer what you're doing.

I'm guessing you want 19 minutes because the ASP.NET timeout defaults to 20 minutes and you want to redirect the user before that happens. If you want to set the timeout to 1 minute less than the ASP.NET timeout, then:

setTimeout(SessionTimeout, <%= (Session.Timeout - 1) * 60 * 1000 %>);

This will also result in a 19-minute timeout for a default ASP.NET session timeout. However, if the ASP.NET timeout is changed, this will change with it, staying as 1 minute less than the ASP.NET timeout.

Simon Forrest
This is partially correct .. when i increase the millisecond its increasing the timeout .. but its not exactly same as what we put there as milliseconds ..timeout happends before that...