ASP.Net Custom session timeout

Asp.net set session timeout in web.config, Global.asax and IIS

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
 
 

Comments

Popular posts from this blog

c# console applicaton progress bar with spinner

Paging, sorting and searching in mvc + razor

C# SELF DESTRUCT CONSOLE APP