ASP.NET session expires before timeout value specified in Web.Config

Note: You can refer this article to know more about different ways to store session state.

There are number of reasons why values stored in session being lost before session timeout value set in web.config.

Are you using In-Proc Session State ?  If Yes, check out following things.

Reason# 1: If ASP.NET encounters any of the following changes, it will recycle worker process and all state data for applications that are stored in process will be lost(so session expires).

  • Machine.Config, Web.Config or Global.asax are modified
  • The bin directory or its contents is modified
  • The number of re-compilations (aspx, ascx or asax) exceeds the limit specified by the <compilation numRecompilesBeforeAppRestart=/> setting in machine.config or web.config  (by default this is set to 15)
  • The physical path of the virtual directory is modified
  • The CAS policy is modified
  • The web service is restarted
  • (2.0 only) Application Sub-Directories are deleted (see Todd’s blog for more info)

Reason# 2: There are few settings in IIS that can cause application pool or worker process to be recycled.

1 ) Right click on application pool that being used for your website and go to properties and check out the following options.

IIS recycle the worker process after certain time period or after X number of requests if those options checked as shown in above screen shot that can cause your session being lost.  Please keep those options in mind and set appropriately based on your need.

2) Go to performance tab and check out following option.

If the option shown in above screen shot checked, please make sure that time set over there match the session timeout value set in web.config.

3) Right on your website -> Properties -> Home Directory -> Configuration -> Options Tab.

This option is only applies to classic ASP application.  So don’t worry about the value set over there.

Reason# 3: If you are using more that one web server(web farms), it is important to remember that all your web requests will not stick to particular web server. For example, if you are making a web request(request# 1), that request will be served by web server 1.  Your another web request(request# 2) may be served by another server web server 2.  Since you are using In-Proc session state, session gets stored in In-Memory of worker process.  So in this case session data gets stored across web server and in incosistant state.  So if you have web farms setup, you need to use Out-Proc session state(StateServer or SQL Server). Don’t know how to setup Out-Proc session state?  This post might help you.

Hope this helps !

Posted in Microsoft Technology Tagged with:

Ads is a trading site of World of Limited. Outback Direct is the official Outback Consumer Warranty, Parts and Accessory Partners for the UK. We currently hold in stock 1000’s of parts and accessories for current and older Outback barbecues. We endeavour to ensure rapid and secure product delivery the length and breadth of mainland United Kingdom, this factor coupled with our excellent customer service has led to the market position we currently enjoy.
outback barbecue
omega 300 gas barbecue
Omega 250 Gas Hooded BBQ
------------------------------------------------------------ Silver Sky Imports is a unique online marketplace that offers unique handicrafts from Tibet and Nepal. Launched in 2003, Silver Sky Imports is currently the largest supplier of handmade items from the Himalayas. We specialize in the largest variety of Tibetan Singing Bowls and Crystal Singing Bowls online and include individual sound samples, pictures and descriptions for each bowl. Some of our other products include Tibetan Prayer Flags, Tingshas, Bell and Dorje, Incense, Felted Wool Handbags, Wood Masks, Prayer Wheels, Gongs, Bronze Statues, and Tibetan Meditation Rugs. monks
------------------------------------------------------------ Airpush, a mobile ad network that is only two years old, has quickly grown to one with over 5,000 advertisers. One thing they've heard from that sea of advertisers over the past 12 months, and especially over the past six, is that real-time bidding (RTB) capabilities are now a must. To answer those needs, the company today unveiled AirDSP, a platform meant to easily connect advertisers to RTB exchanges. Read more: Mobile RTB
------------------------------------------------------------ Danish site about electronic cigarettes E Cigarette, Electronic Cigarette and E Cigarettes e cigaret
------------------------------------------------------------ drugrisk​ recall ​informat​ion​ drugrisk​ yaz​