Why ASP.NET sessions are lost unexpectedly after a short time? Print

  • asp.net, asp.net session, InProc Session, session loss, session state, plesk windows, iis application pool
  • 1

In ASP.NET applications hosted on Windows hosting packages of Provider.lk, sessions may appear to be lost unexpectedly. This typically occurs when the IIS application pool recycles, which is normal behavior in shared hosting environments.

Why Sessions Are Lost

By default, ASP.NET uses InProc session state mode (see Session-State Modes for more info). In this mode:

  • Session data is stored in the memory of the IIS worker process
  • When the IIS application pool recycles, all in-memory sessions are cleared

Common Causes of Application Pool Recycling

  • Scheduled IIS recycling (default ~29–30 minutes)
  • Memory usage limits reached
  • CPU usage limits reached
  • Web.config or bin folder changes
  • Server maintenance or restarts

In shared hosting environments, resource-based recycling is common and outside the control of the users. To prevent this, you have to use persistent session storage (Why you shouldn't use InProc session state).

Persistent Session Storage Options

1. Client-Side Session Alternatives (Recommended)

Because persistent server-side sessions are not guaranteed on shared hosting, our recommendation for the Provider.lk Windows hosting customers is to use;

  • Authentication cookies
  • Encrypted cookies for small session data
  • JWT tokens (for authentication scenarios)

These approaches do not rely on IIS memory, survive application pool recycles and are fully supported in shared hosting. If this is not an option, you can consider one of the following alternatives.

2. Alternatives

Request a resource upgrade: Contact us to discuss increasing your hosting resources. This can reduce the frequency of IIS pool recycling due to CPU/memory limits. Please note that additional fees may apply due to increased resource usage.

Optimize resource usage: Reduce the load on your account by removing other applications, especially PHP applications, and dedicate the account to a single purpose.


Was this answer helpful?

« Back