Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
session time handling how to time extended.
Posted
Updated 28-May-12 19:00pm
v2
Comments
Prasad_Kulkarni 29-May-12 1:09am    
downvote countered

By default, Session timeouts are set to expire in ASP.NET in 20 minutes.
To increase the timeout or expiry you should change the timeout attribute for SessionState in the web.config file

C#
<sessionState  timeout="40" />


Note that if you are using Forms authentication, the Forms timeout setting will log the user out after the set timeout period so you will also have to adjust this attribute:

HTML
<authentication mode="Forms">
          <forms timeout="40"/>
    </authentication>


Redirecting user to login page after session timeout is similar to refreshing the page after certain intervals method. Only thing which will differ is that calculating time after which the page has to be redirected. Hence time can be calculated using Session.timeout property which will give us session timeout value for that session. Add some grace timings to that value and redirect the user to the login page automatically.

Using Window.setTimeout method
In the page Load event:
C#
body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 10000 & ");")


Using Meta Tag - Refresh

C#
Response.AppendHeader("Refresh", Convert.ToString((Session.Timeout * 60) + 10) & "; URL=Login.aspx")

Both these methods will redirect the user to login page after session timeout + 10 seconds. This is how you can redirect the user to login page after session timeout without user interaction.

Also refer some CP articles for more details:
Session management options in ASP.NET[^]
Session Management in ASP.NET[^]
 
Share this answer
 
Comments
P.Salini 29-May-12 1:51am    
my 5
Prasad_Kulkarni 29-May-12 1:57am    
Thank you Salini!
Rahul Rajat Singh 29-May-12 2:16am    
Good answer. +5
Prasad_Kulkarni 29-May-12 2:19am    
Thank you Rahul!
Rahul Rajat Singh 29-May-12 2:21am    
you are most welcome.
see this link you may get some idea
Alert Session Time out in ASP.NET[^]
 
Share this answer
 
if you are using inproc than you can increase timeout of session in webconfig file by adding these line:-

HTML
<system.web>
<sessionstate mode="InProc" timeout="60" />
</system.web>


and now i am giving you link that will give you more idea on sessions

Session Time out in ASP.NET[^]


Exploring Session in ASP.NET[^]
 
Share this answer
 
You can handle session time in web.config

C#
<system.web>

.......

<sessionstate timeout="1440"></sessionstate>

</system.web>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900