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 asp.net 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
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
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
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.