Refinance now before rates go up! Get multiple rate quotes at GetMyLender.com.

ASP.NET Webdomain Recycles Automatically on Deletion of Sub-directory

While working on a web application, once upon a time I was presented some weird behavior on ASP.NET.

In ASP.Net web application, When you delete a directory the session gets expired automatically. This is one of the frustrating error. It is the default nature if you are deleting a sub-directory within your application, your app domain will restart. This removes all session data.

Following observations will help you to find base of this issue:
- Session times out randomly while working on the application.
-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 found that a certain implementation use to create folder, put some temporary files inside it and once done, the folder and the files were deleted. The application recycles whenever the folder is deleted.

What is the technical reason behind expiration of session after deleting folder?

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.

How to overcome this issue?

There are multiple solutions that can be taken up to resolve this issue.

Solution 1: Use out of process session state

All session expires on application recycle unless the state is not in-process. So moving state in-proc to out-proc is a solution.

Solution 2: Pointer to External Folder (Directory Junction)

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

Solution 3: Using Registry Editor

You can follow below steps to open Registry Editor:
-Open Run Window by clicking on (Win + R) button.
-Type regedit .
-Press Enter button from keyboard or OK button from window

Disable FCNotifications in ASP.NET 2.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: 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 sub-directory, the application will create an object that will monitor the sub-directory.
0 or greater than 2 This is the default behavior. For each sub-directory, the application will create an object that will monitor the sub-directory.
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 sub-directory.

Solution 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 this solution no 4 for the time being.

Solution 5: Programmatically stop File Monitor (FCN)

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. So, we can stop File Monitoring programmatically.

For details of this solution, please Click Here : How to Maintain Session in ASP.NET application after deletion of sub-directory.


Conclusion :

I hope that this article would have helped you to learn various methods to maintain Session in ASP.NET application after deletion of directory. Your feedback and constructive contributions are always welcome.


No comments:

Post a Comment