Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to expire the session after some time?
Posted
Comments
[no name] 7-May-14 9:54am    
It's a old topic. You will get tones of topic from google. and it so simple to set into in web.config file

Several ways:
1. You can change session timeout value in web.config. Example, if desired session timeout is 20 minutes, markup code in web.config should look like this:
XML
<sessionstate timeout="60" mode="InProc""></sessionstate>

SessionState element is located under
XML
<system.web></system.web>
namespace.
you can change ASP.NET session timeout programmatically
2. you can change session timeout from code. example, to decrease session time to 10 minutes, use:
C#
Session.Timeout = 10;

3. One more way to change session timeout is using IIS Manager. Open Control Panel -> Administrative Tools -> IIS Manager -> Select desired web site -> in ASP.NET section on right side open Session State -> and finally, in text box named "Time-out (in minutes)" on the bottom of the form, change default value. This is the method if you use IIS 7, but it is similar for earlier versions too. On IIS 6, right click on selected website -> choose Properties -> in pop up dialog select ASP.NET tab -> and change timeout value.
4. if you use Forms Authentication, you'll probably need to increase forms timeout too, using markup code in web.config like this:

XML
<system.web>
      <authentication mode="Forms">
        <forms timeout="60" />
    </authentication>

Hope it helps
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 7-May-14 8:32am    
Forms timeout will not kill the session before session timeout, but will force user to login again on the same session...
Schatak 9-May-14 1:12am    
its just an alternate if such situation arise
your time in minutes

Session.Timeout = 20;
 
Share this answer
 
Set Session.Timeout using code or your web.config...
This sample set it to 30 minutes!
XML
<configuration>
  <system.web>
    <sessionstate mode="InProc" timeout="30" />
  </system.web>
</configuration>
 
Share this answer
 
Comments
Laiju k 7-May-14 8:10am    
Session.Timeout = 20;

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