Saturday, September 17, 2011

How to increase session timeout in asp.net


Increase session timeout in ASP.NET by using this code. Put this code in web.config file. 
 
<system.web>
<!-- Increase session timeout  -->
<sessionState mode="InProc"  stateConnectionString="tcpip=127.0.0.1:42424"  cookieless="false"   
  timeout="120"/>
</system.web>
This will increase the session timeout to 120 min. By default session timeout is 20 min 
 
or
 
<system.web>
  
    <sessionState mode="StateServer" stateNetworkTimeout="10" 
sqlCommandTimeout="30" cookieName="ASP.NET_SessionId" timeout="53200" 
regenerateExpiredSessionId="False">
      <providers>
        <clear/>
      </providers>
    </sessionState>
    <httpRuntime executionTimeout="9999" maxRequestLength="10240"/>
    <machineKey validationKey="409B3A07F360A34A7C5DDD40B317AF7BBD7904A1E3D68273A9AC320BAE312D39619A28443AAF92E16A88BC66BF5AAF543C33723581EAD1378DEA9653C44868FC" 
decryptionKey="EA09335756D695E538762FABB50FE581AFA525C4B485AC51E450D95DD813303E" 
validation="SHA1" decryption="AES" />
    </system.web>
 
 

Generate your Machine Key 
it will be unique so generate your own key from the below link and 
paste in web.config file


http://aspnetresources.com/tools/machineKey
 
in global.asax
 void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        // Code that runs when a new session is started
        Session.Timeout = 53200;
    }