ASP.NET webdomain recycle on subfolder changes

While working on a web application, one of my team presented some weird behaviour on ASP.NET

FIrst observation: Session times out randomly while working on the application.

So we started observing the application closely to see what might be causing this. We came out with some more observations:

Detailed observation: Session times out when any of the user participates in certain scenario. Also, not only the specific session expires, but all the use sessions are expired. Further study shown that actually the app domain itself recycles.

We studied the activities in these specific scenario. We found that a certain implementation use to create folder, put some temporrary files inside it and once done, the folder and the files were deleted. The application recycles whenever the folder is deleted.

The technical reason: ASP.NET runs a File Monitor (FCN) that observes any change to the structure of the Virtual Directory. In case of any change the application is recycled.

Some forums said that tghe app_data folder within the application folder is immune to the condition. But upon testing, we found it otherwise.

Analysis: Lots of analysis:

Also we were observing session expiration initially. All session expires on application recycle unless the state is not in-process. So moving state in-proc to out-proc is a solution.

We found some other approaches as well.

Resolution: There are multiple solutions that can be taken up for this:

Compiled Solutions / workarounds so for

Sol 1: Use out of process session state.

Sol 2: Use Directory Junction between seperate Web folder and content folders. A directory Junction is a pointer to an external folder (outside the application folder/sub folder.

loadTOCNode(3, 'resolution'); To enable this hotfix, you must add the following DWORD value at the following registry key:
HKLM\Software\Microsoft\ASP.NET\FCNMode

The following table lists possible values for the FCNMode DWORD value and the behavior that is associated with each value.
Value Behavior
Does not exist This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory.
0 or greater than 2 This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory.
1 The application will disable File Change Notifications (FCNs). Smile
2 The application will create one object to monitor the main directory. The application will use this object to monitor each subdirectory.