Gordnfreeman
Gordnfreeman

Reputation: 1615

Setting time for a session to timeout

I know that this question has been asked a lot on here but none of the solutions that people offered seemed to really work for me. I am trying to extend the length of time that sessions remain active on my website I tried modifying web.config with:

  <sessionState timeout="45"/> 

And setting Session.Timeout in the code behind but nether of those worked as intended. I would like to get the sessions to last as long as possible, but as of right now they last about 10 minutes before i start to have issues.

Upvotes: 1

Views: 2120

Answers (2)

Prince Antony G
Prince Antony G

Reputation: 932

Asp.Net Session Management has two Modes.

InProc

Loss of Session is a common problem in this mode. IIS keep recycling the worker-process after some duration, which causes the loss of Session Data.

Have a look at below link for more informaton on this.

Check this

Below CodeProject article has a work-around for this problem.

Prevent Session Timeout in ASP.NET

OutProc

In this mode of Session Management, settings of web.config will work properly. Have a look at below link for more details.

check this

In WebConfig :

<configuration>
  <system.web>
     <sessionstate timeout="20" /> 
  </system.web>
</configuration>

By default its 20 mins. Change it as per your needs.

Check it in IIS

  1. Open the IIS, click on the Application Pool.

  2. Select the Application pool for your application.

  3. Right Click --> Select Properties. In the Performance tab, Set the idle timeout as your desired minutes for "shutdown worker processes after being idle for ..... minutes".

Restart IIS after that.

Why Session.Timeout is not working for your website

Upvotes: 2

competent_tech
competent_tech

Reputation: 44931

If your session state is setup to be InProc and you have multiple web servers or a web garden, then your session state could easily be lost.

See the MSDN documentation for more details.

Upvotes: 4

Related Questions