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;
    }

6 comments:

  1. Anonymous06:20

    good

    ReplyDelete
  2. Hi Raj, but this is not working. Now what to do?

    ReplyDelete
  3. Can you send me your sample code at rajahuja10@gmail.com

    ReplyDelete
  4. hello raj,
    i am using a shared server and i am having the problem in session time out as the default time of server session timeout is 20 min but i wants to keep session alive till he is logged in on the application.

    can you please suggest me some solution for this problem

    ReplyDelete
    Replies
    1. Use this code
















      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;
      }

      Delete

Note: Only a member of this blog may post a comment.