ASP.NET’s Built-in Maintenance Page
This was originally posted on vanslaars.com in April of 2006.
Web applications require updates, maintenance and sometimes there are problems behind the scenes that require an app be taken offline temporarily. In the past I have accomplished this by setting my IIS default documents to index.html and default.aspx, in that order. My applications always use Default.aspx as the home page and I leave a file called “_index.html” sitting in the root directory. This html file contains a standard message letting users that the system is temporarily down. When I need to perform maintenance, I rename “Default.aspx” to “_Default.aspx” and remove the underscore from the html file to leave “index.html” as the default page for the application. This stops bookmarks to Default.aspx from working and displays the error message.
This approach works reasonably well, but it has some inherent problems. For one, the application continues to run, so bookmarks to other pages in the site continue to work. People looking for “Default.aspx” will get a 404 (page not found) error, and renaming both files is more work than I care to do for such a common need. Well, ASP.NET 2.0 comes to the rescue again with a very simple, yet elegant solution…the “App_Offline.htm” file.
Placing a file in the application root with the name “App_Offline.htm” causes the application domain to be unloaded and requests stop being processed. There is no need to rename any files, or change anything in the application. Just add the file and all requests will be directed to that file. Place your friendly message there, upload the file and perform your maintenance. When you are done, remove the file and the application runs normally for the next request.
The nice thing about this is that you can keep the file off of the server, FTP it up when you need it and delete it when you are done. The local copy can be used again in the future and no files need to be moved or renamed for the application to start again. There is also no requirement to change any setting in IIS.
Who would have thought a simple html page would become a key tool for application maintenance?