BlueDragon Blog
Here you'll find tips and information about making the most of BlueDragon, which offers several compelling implementation alternatives for your CFML applications. This blog was created originally by Charlie Arehart, who was New Atlanta CTO from 2003-2006.,He has since moved on to become an independent consultant but continues to answer comments raised in existing blog entries. BlueDragon continues, and you should look to the newer BlueDragon blog, from New Atlanta president, Vince Bonfanti, for more updated information.

Why might a .NET web application (app domain) restart? The reasons may surprise you

posted Tuesday, 14 June 2005

If you're running an .NET web application and experiencing problems, one thing to investigate is whether your web app is restarting more times in a day than you expect, and if so, why? If you're finding that sessions seem to be ending too quickly, or pages are very slow to start every once in a while, this could be the cause (and it could explain other problems as well).

Is the App Restarting?

It's simple to see (in aggregate) whether .NET web apps are restarting, either by viewing PerfMon to view the "application restarts" statistic, or by running code to view the stat using the .NET framework's System.Diagnostics.PerformanceCounterCategory class.

The "performance object" to view (in Perfmon) (or the "category name" in the PerfomanceCounterCategory class) would be ASP.NET or ASP.NET v1.1.4322 (or similar, for 1.1) or ASP.NET v2.0.40607 (or similar, for 2.0).  Look specifically at the counter "Application Restarts". If it's non-zero, you've had a restart since IIS itself has been restarted. (Of course, if IIS itself is restarting, you need to look to other counters or could use the System.Web.ProcessModelInfo class to view its AGE property for the lifespan of the current process.)

Note that this is NOT the category called "ASP.NET Applications" and its corresponding 1.1 and 2.0 variants. Those track individual app domains, but do not include a restarts counter. Conversely, the object/category above is global for all apps, so doesn't work as well if you have many different web apps (web sites, virtual directories).

One last tip on viewing this info in Perfmon: When viewing numbers like this I prefer to switch to the "report view" (Ctrl+r) which shows raw numbers rather than a graph or histogram.

Why is it Restarting?

If you see that you are experiencing restarts, the next question to ask is why? When folks work with .NET web apps, they often learn the hard way that their app is restarting more often in a day than they'd expect. The reasons it can happen are even more surprising.

Among the reasons it can/will restart (or technically, unload itself) is if:

  • the web.config is edited
  • the machine.config is edited
  • the global.asax is edited
  • files are changed in the bin directory of the web app, or one of the bin's subdirectories
  • a directory is created, renamed, or deleted within a web app directory
  • an ASP.NET file (aspx, asmx, etc.) is edited (and therefore recompiled) more than 20 times, a default set in the machine config as an element named numRecompilesBeforeApprestart
  • by way of settings of various attributes in the <processModel> element in the machine.config, which affect the restart/shutdown of the worker process itself. On Windows 2003, when not using IIS5 isolation mode (which is not used by default), these <processModel> elements are ignored and instead the settings in Application Pools in IIS manager are used

This isn't even a complete list, but it's one that's been developed from experience.  The number and kind will surprise most folks. For instance, if you have as part of your web app design a process that creates (or renames or deletes) directories, you will be restarting/unloading the web app each time. You may want to redesign things to permit storing the files/directories outside the web app. These are simply facts of life with .NET. You should just beware of them as you consider .NET web apps. (For users of BlueDragon/.NET, note that the issue of edit/recompiling ASP.NET pages does NOT apply to CFML pages.)

It's worth noting, by the way, that if you try to make the changes above and see no change in the restart counter, it could be simply because these actions "unload" the current web app, so you won't see an increment in the counter unless the web app you're testing against has been reloaded (by making a request for a page in the web app). 

Forcing a Restart Manually

One last point to make is that if you want to force a restart of (or again, techically, unload) the current web app/app domain, run the following code (call it unload.aspx, for instance):

<%@ Page Language="c#"  %>

<% System.Web.HttpRuntime.UnloadAppDomain(); %> 
Restarted at <%= System.DateTime.Now.ToShortTimeString() %>

It will unload the domain in which it's located (if it's in a virtual directory, it will unload THAT app domain and not that of the web site in which its located.) Note that I'm also outputting the current time. You may find that if you revisit this page in your browser, you may inadvertantly see a cached version of the output of a previous restart. Be sure to check the time shown against the current time.




1. Jasdeep left...
Thursday, 28 July 2005 7:04 pm

What if it is restarting itself at exactly the same increment in time, even though the site is being hit and no files or directories have changed at all. I have three different apps that are all restarting after exactly 1 day and 5 hours give or take about 5 minutes. I have been trolling through the internet to find a reason for this, but still no luck.


2. joseph spaur left...
Friday, 26 August 2005 3:45 pm :: http://www.recruitmax.com

Jasdeep, ASP.NET will restart itself manually every 1740 minutes (1 day plus 5 hours (29 hours total))...if you go to the application pool in which you're using for BD.NET and look at the Recycling tab you should be able to change when ASP.NET auto restarts....feel free to email me if you have any questions.


3. Charlie Arehart left...
Wednesday, 11 January 2006 6:33 pm

It turns out that yet another cause of seeming "loss" of sessions is related to the use of IIS 6's "web gardens" feature. See this entry here for more:

http://bluedragon.blog-city.com/lost_sessions_webgardens_sessionst ate.htm