Saturday, March 31, 2012

When App_Offline.htm does not work as advertised

If you ever have had to do maintenance on a public web site, you have probably used the App_Offline.htm feature at least once.  For those of you who are not aware of the App_Offline.htm feature, it is a feature introduced with ASP.Net 2.0 to essentially shut down your website and prevent it from accepting requests (perfect for performing maintenance tasks and updates on your site).  This was originally described by Scott Guthrie in this blog post:

However, I encountered an issue with the use of this feature that did not conform to expectations.  I was specifically using the App_Offline.htm to capture all requests to my website while I was performing an upgrade.  As you can guess, the upgrade involved an overhaul of the website including numerous changes to assemblies in the bin directory.

Since my site is hosted by a 3rd party hosting provider, I was uploading the content via FTP.  Well, unfortunately, uploading the bin directory containing all of the new assemblies introduced compilation errors into the website.  I also had customErrors turned off in my web.config file.  Therefore, even though my App_Offline.htm file was present in the root of my website, the compilation errors introduced into my website through uploading the bin directory continued to display the various compilation error messages rather than the "Under Maintenance" message I had created in my App_Offline.htm file!

Even when I turned on customErrors in my website, I simply got the generic customErrors message regarding an error in the website.

Of course, once I had completed uploading all of the content on my website that resulted in a successful compilation, my App_Offline.htm file once again performed as expected and displayed the "Under Maintenance" message.

Therefore, if you are making drastic changes to your publicly hosted website, it is better to simply shut down the website and rely on some other type of maintenance message (perhaps through an IIS redirect) rather than completely relying on the App_Offline.htm file to display your Under Maintenance message.

No comments:

Post a Comment