Wednesday, August 13, 2008

App_Offline.htm - How to Redirect user to "Down for Maintenance" page in ASP.NET ?

Usually there arises a scenario when we want to upgrade our production site to a new release, and want the users to be redirected to the “Down for Maintenance” page.

The best way to implement this is using the app_offline.htm file. ASP.NET 2.0 has provided a fantastic functionality using which the users will automatically be redirected to the “Down for Maintenence” page. Just add a HTML file named “app_offline.htm” to the root directory of your web site. Adding this file will clear the server cache. When ASP.NET sees the app_offline.htm file, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the app_offline.htm file in response to all new dynamic requests for the application.

Please take a note that the size of the file should be more that 512 bytes to be displayed. If the size of the file is less that 512 bytes, then manually IE Browser settings need to be changed. The "Show Friendly Http Errors" check box from the Tools->Internet Options->Advanced tab within IE needs to be unchecked. If this check-box is not unchecked and the app_offline.htm file size is less that 512 bytes, then the IE “Page cannot be displayed” message will be shown.

To start the web site again, just remove this file from the root folder of your web site. This will trigger the asp.net engine to cache all the page contents and display the pages. This has really made life simple :)

Hope this helps! Your comments are always welcome!

3 comments:

Anonymous said...

Good one... Thx!

Eric Moreau said...

It is not 512 KB but really 512 bytes! You can pad your file with comments if you don't have this minimal size.

Sandeep Aparajit said...

Thanks Eric Moreau..
Updated the article :)

Post a Comment