App_Offline.htm
November 25, 2009 Leave a Comment
There is a handy way of taking an asp.net 2.0 application offline immediately. It is not that well known but all you have to do is place a app_offline.htm file in the root directory of your web application. Thanks to Scott Guthrie blog for the info…
Placing the app_offline.htm into the root directory 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.
It is also useful to know that the app_offline.htm file is also used when you publish a web app to an IIS webserver. Visual Studio takes care of placing an app_offline.htm file into the root directory and removes it after the publishing has completed. By default the following text is displayed from the htm file..
“This application is currently offline. To enable the application, remove the app_offline.htm file from the application root directory”.
Visual Studio uses an app_offline.htm file that is stored in [User Document/Settings Path]\Application_Data\Microsoft\VisualStudio\8.0\ so if you want to customise the message that is displayed during a Visual Studio project build & deploy then just customise the file in any way you want.