Tuesday, 22 July 2014

How to set custom session timeout in asp.net?

By default our websites session timeout is 20 minutes after that session will gets expire suppose if we want to set our custom timeout in our applications.

We can set timeout in different ways:
  • From web.config
  • From global.asax 
  • From 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, we 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

No comments:

Post a Comment