Deleting ASP.NET 2.0 Application Sub-Directories Shuts Down the AppDomain

This issue seems to be coming up recently since ASP.NET 2.0 shipped; probably because this behavior has changed from previous versions. In previous versions ASP.NET did not care if you deleted sub-directories of the web application and it appears some folks actually depended on this behavior and now when upgrading to ASP.NET 2.0 are finding their AppDomains are restarting after deleted a sub-directory.

 

The problem stems from the fact we have changed what actions we taken when monitoring File Change Notifications (FCN) in ASP.NET 2.0. The change was made so that when you delete a directory, either through Explorer or within the VS designer, stale content would not continue to be served. For example, suppose an application has a Virtual Directory definition that points to c:\webRoot and you have a sub-directory c:\webRoot\someDir. When you deleted someDir the AppDomain will shutdown with ASP.NET 2.0 but not with ASP.NET 1.0 or 1.1. Note that upon the very first request to that application the AppDomain will restart again. 
 

ASP.NET 2.0 uses a FCN that monitors for changes to the application root and all changes under that directory. At the time of this writing there is no fix to the product to change or revert the FCN behavior. If you find you need to delete an application sub-directory you need to block this behavior using a Directory Junction.

 

Let’s extend the sample web application used previously, let’s suppose I want to be able to create and delete files and directories within a directory under my web application at c:\webRoot. For this sample I consider these files and directories my content so I will create a directory named content such as c:\webRoot\CONTENT. I then create another directory which is really where my content will be stored at c:\MyWebContent. This sample assumes my C: drive is formatted as NTFS. I now need to create a directory junction between c:\webroot\content and c:\mywebcontent by using a utility called linkd.exe. The Linkd.exe utility ships with the Windows Server 2003 Resource Kit and can be downloaded from here.

 

Linkd is a command line utility and takes only a couple of parameters. To create a directory junction for my sample I run the command as so:

Linkd c:\webroot\content c:\mywebcontent

I pass linkd the source and the destination directories. Once created the directory junction graphs the contents of c:\mywebcontent into c:\webroot\content. So when I manipulate directories and files from either c:\webroot\content or c:\mywebcontent these changes are not reported back to the FCN monitoring c:\webroot. If however I delete or modify any content directly under c:\webroot the FCN will pick up these changes and restart the AppDomain so I need to ensure the changes are occurring under my content folder.

 

File change notifications do not follow the directory junction on Windows 2003 Server and Windows XP. I have not tested with Windows 2000 and would be interested to hear from the community if anyone has given this a try on that OS version.

 

For more information on NTFS directory junctions please refer to the KB article:
How to create and manipulate NTFS junction points