This might be “old hat” for most of you experienced ASP.NET Developers out there – but I think it is worth another blog entry as I just ran into the following problem:
Step 1: Migrated an Application from .NET 1.1 to .NET 2.0
I worked with an ASP.NET Application originally developed on ASP.NET 1.1. We upgraded to . NET 2.0 using Visual Studio 2008 and the project conversion wizard. Besides some problems with the conversation of project files and web service proxies – that could all be fixed manually – the conversion went smoothly. The application could be started without any problems and seemed to work fine – at least as long as we did not modify the data in the file based data store. All these transactions seemed to cause the loss of all our current ASP.NET Sessions.
Step 2: Debugging through the code
A debugging session showed us that the reason for the lost ASP.NET Sessions was an unexpected recycling of the AppDomain which led to the loss of any currently active sessions. Unfortunately we couldn’t see any reasons why the AppDomain was restarted. There were no severe exceptions nor did anybody change the web.config file on the fly (which would cause a restart).
Step 3: Reading blog entries about AppDomain Recycling
There are a number of blog entries that describe why AppDomain’s might get recycled. And some of them explained a change that happened from .NET 1.1 to .NET 2.0:
- ASP.NET Case Study: Lost session variables and appdomain recycles
- ASP.NET v2.0 – AppDomain recycles, more common than before
Step 4: Identifying our problem
So it turned out that due to the File Change Notifications on the WebRoot directory and all subdirectories AppDomains will now be recycled in case any file in this directory or subdirectory is changed/added/removed. In .NET 1.1 this was not the case – only certain files were checked for modification, e.g.: web.config.
The ASP.NET Application on our hands used a single file based database that was stored in the bin directory of our ASP.NET Application. When changes were commited to the DB and the ADO.NET driver committed those changes to the file system the File Change Notification triggered an AppDomain restart and we lost all of our current ASP.NET Sessions.
Be aware of this change in AppDomain recycling when migrating an older ASP.NET 1.1 Application to ASP.NET 2.0