Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Asp.net set session timeout in web.config IIS

Oct 2, 2010
Introduction:

Here I will explain how to set session timeout in web.config,IIS and in application using asp.net manually.

Description:

By default our websites session timeout is 20 mins after that session will gets expire suppose if we want to set our custom timeout in our applications we can set it in different ways (web.config, global.asax and in IIS)

Check below methods to set session timeout in web.config, global.asax and in iis

In Web.config file we can set session timeout like as shown below 

<configuration>
<system.web>
 <sessionState mode="InProc" timeout="60">
 </sessionState>
 </system.web>
</configuration>
In  Global.asax file we can set session timeout in Session_Start event like this

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session.Timeout = 15;
}
In IIS setting you can also set default session timeout.

     1) Open IIS start-->run type-->inetmgr and press enter.

     2) Right Click on "Default Web Site" go to properties

     3) Select Asp.Net tab, click on "Edit Configuration" Button 

     4) Select "State Management tab" in new popup window

     In case if you are using IIS7

     Select Default Web Site >> Click on Session State

     Once open Session State set timeout in under cookie settings section like as shown below
  
If you set session time out in both web.config and in your iis the iis session out value overrides web.config session time out

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

7 comments :

Anonymous said...

I have been facing this problem since many days, now its solved only becoz of U

Thank U so much

RAJNISH TIWARI said...

it is not working using webconfig
































RAJNISH TIWARI said...

Please reply this coding is not working in webconfig file or global.asax file

Asif Iqbal said...

This code need some correction.
However it logically excellent
Correct code is:
<sessionState mode="InProc" cookieless="true" timeout="60">
</sessionState>

Note; closing tag and white space at timeout was the problem.

Also code at
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session.Timeout = 15;
}
doesnot works at all.

srujan said...

hi sir, thanks for your beautiful explanation of each topic. I have a small doubt in this topic about of time we are giving. Is it in seconds or in minutes? (in webconfig and in global files)

Suresh Dasari said...

@Thanks Asif... for finding my error

@rajnish... i updated the code...Please check it

ankur shukla said...

send me the full code fro session time out on logout button click in.simple asp.net aspx page and .cs page...
my id is ankur03shukla@gmail.com

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.