[.NET 2.0] Taking a Web App Offline

This is a neat feature of ASP.NET 2.0 I just found out about. Loads of people have already written about it, but it's so useful that I decided to put it on my blog as well. By placing a file called 'app_offline.htm' in the root directory of your web app, no ASP.NET dynamic pages are no longer served. The web server returns the content of that file instead. This is what ScottGu wrote about this feature on his blog:

Basically, if you place a file with this name in the root of a web application directory, ASP.NET 2.0 will shut-down the application, unload the application domain from the server, and stop processing any new incoming requests for that application.  ASP.NET will also then respond to all requests for dynamic pages in the application by sending back the content of the app_offline.htm file (for example: you might want to have a “site under construction” or “down for maintenance” message).

This provides a convenient way to take down your application while you are making big changes or copying in lots of new page functionality (and you want to avoid the annoying problem of people hitting and activating your site in the middle of a content update).  It can also be a useful way to immediately unlock and unload a SQL Express or Access database whose .mdf or .mdb data files are residing in the /app_data directory.

Once you remove the app_offline.htm file, the next request into the application will cause ASP.NET to load the application and app-domain again, and life will continue along as normal.

You may want to read all the comments to this blog entry, some interesting conversation there.

I just happened to stumble upon this feature when I was publishing my web app directly from within VisualStudio (Build->Publish...), because VS automatically places that file in the web app during upload of the new files. Neat. What is not so neat is that VS didn't remove the app_offline.htm file once it was done publishing :) Maybe it was because I was publishing to an FTP site... not sure. Will try again some other time.

No Comments