ASP.NET webdomain recycle on subfolder changes

Posted by

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.

See for more details

Sol 3: Disable FCNotifications in ASP.NET2.0 by adding DWORD FCNMode =1 under HKLM\Software\Microsoft\ASP.NET key

Registry information

loadTOCNode(3, 'resolution'); To enable this hotfix, you must add the following DWORD value at the following registry key:

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.

More info at:  

Sol 4: Do not delete any folder.

Most of the time solution 4 seems to be easy way out till MS releases fix for this problem. So we are following solution no 4 for the time being.

Further reading:

Leave a Reply

Your email address will not be published. Required fields are marked *