Session Loss due to Application Domain recycle- Basics
Published Feb 15 2019 05:35 AM 2,816 Views

This is one of the most common issues that I see a lot and thought will blog about one of the reasons responsible for session loss.

You might have observed sometimes that the application seems to be working fine and you observe one of the below 2 outcomes.

1) Intermittently one of the requests takes a lot of time and it recovers on its own for the next request and so

2) Session loss issues intermittently. The objects you store in the session are lost intermittently and sometimes you might receive null reference exception.

Ideally the first request for an application takes more time compared to the upcoming requests as I need to create an application domain within the process. Application domain is a processing environment within the process where your code is loaded and request is processed. This domain is the same place where your process specific objects are also stored. If you are using in-proc mode for session state, then those session objects also reside in this part of the process. So in case even your process is intact and just application domain within the process recycles or goes down, you might observe session loss as mentioned above


How to detect if the application domain/app domain is getting recycled?

You can follow one of the below steps

Step 1:

Enable health monitoring using the below steps.

Go to C:\WINDOWS\Microsoft.NET\Framework'x'\vy\CONFIG directory and add the following to the <healthMonitoring><rules> section

<add name="Application Lifetime Events Default" eventName="Application Lifetime Events"

provider="EventLogProvider" profile="Default" minInstances="1"

maxLimit="Infinite" minInterval="00:01:00" custom="" />

Note: x is ‘32’ if 32 bit app and '64' if 64 bit app and y is ‘4.0.30319’ if .net 4.0 app and ‘2.0.50727’ if it is .net 2.0 app



Step 2:

Also you can enable the event logging on app domain recycling in code as suggested the below blog

Step 3:

You can add a Perfmon counter and monitor your server as below
1) Click Windows Start button -> Run. Type Perfmon and click Ok.
2) Expand Performance Logs and Alerts.
3) Right click Counter Logs and select New Log settings.
4) Type a name and click Ok.
5) Click on Add Counters button.
6) From the Performance object select ASP.NET v.1.1.4322 or the ASP.NET version of your application.
7) Choose Select counters from list and select Application Restarts.
8) Click Add, Close, and Ok.
9) You will notice that the Perfmon will start logging data into this log file.

Once the issue happens you would observe the counter increasing.


Most common reasons for App domain recycling:


1) Antivirus Scans: You can get rid by excluding your framework, Application directories from scanning

More info on the directories to be excluded from antivirus scan can be found in the below blog
2) Group policies changing or modifying framework folders or application folders either the permissions or the folder contents
3) Machine.Config, Web.Config or Global.asax are modified
4) The bin directory or its contents is modified
5) Exceeding the number of recompilation.

Usually by default the number is 15 and you can check this under numRecompilesBeforeAppRestart tag in machine.config or web.config: numRecompilesBeforeAppRestart property Gets or sets the number of dynamic recompiles of resources that can occur before the application restarts.

6) The physical path of the virtual directory is modified
7) The CAS policy is modified.
8) The web service is restarted.
9) Application Sub-Directories are deleted.

10) Writing files within web application or website directory.

These are some of the basic checks we can do to identify if the issue we are facing is because of Application Domain Recycling.

In the next series of blogs I am going discuss how to collect much more advanced data and how to look into these data to identify the root cause.

Hope this helps Smile

Author: Chiranth Ramaswamy

Version history
Last update:
‎Feb 15 2019 05:35 AM
Updated by: