0

I am using a session to pass a variable but on the server after logging in the session automatically expires after 2 -3 minutes, What could be the problem?

The webconfig file:

 <sessionState  timeout="1440" mode="InProc"></sessionState>
    <authentication mode="Forms">
        <forms name="School" loginUrl="Login.aspx" defaultUrl="default.aspx" 
               timeout="1440" slidingExpiration="true" protection="All" path="/" />
    </authentication>

I changed the timeout but it does not work.

Joel Purra
  • 24,294
  • 8
  • 60
  • 60

3 Answers3

1

Enable and check the logs and performance counters if the application pool restarts for some (configurable) reason, and loses it's sessions. Examples include if it runs out of memory (more likely if you have a shared app pool), if you have too many errors per minute (possibly "hidden" errors, triggered by for example search engine spiders) or if you are making changes to observed files or in observed folders (like web.config or bin\).

Depending on your session "uptime" requirements, since restarting the application pool will drop ("expire") all of your in process sessions, you could "fix" the issue by using an out of process session state store, like ASP.NET/Windows State Service/Server or SQL Server.

If you feel it's an IIS configuration or server issue more than a code issue, you can always ask on ServerFault.

Community
  • 1
  • 1
Joel Purra
  • 24,294
  • 8
  • 60
  • 60
0

Your timeout settings for Session and Forms looks fine but there are still many things can go side ways which causes you to think session is timed out. I suggest you to investigate the issue as follows:

Network setup: if your servers are load balanced, make sure the configuration will work with session.

App Pool: Check your application pool refresh/reset rules on IIS. Make sure there is no setting to refresh the pool every 20 requests or the likes.

Task Manager: Look at task manager and see how the IIS worker process doing (w3wp.exe). Is it getting killed off by antivirus program? If so, session will be timed out for sure.

Event log: Lastly, take a look at windows event log. see if there are event entries related to time out.

Ray Cheng
  • 12,230
  • 14
  • 74
  • 137
0

Add this to your Global.asax.cs

 protected void Session_Start(object sender, EventArgs e)
        {
            Session.Timeout = 240;
        } 
Ashwin Singh
  • 7,197
  • 4
  • 36
  • 55