Little-heard-of ASP.NET feature: app_offline.htm
By rickvdbosch
- 3 minutes read - 483 wordsAlthough the feature has been around since ASP.NET 2.0, I still meet people that don’t know and/or use app_offline.htm. Do you know (and use) the feature…?
When working on an ASP.NET web application, you should notify your visitors in a decent way that your application is down. There’s a nice default feature available for these purposes since ASP.NET 2.0. Somehow, however, this feature is not very well known and rarely used. The App_Offline.htm
feature in ASP.NET 2.0 provides an easy way to bring down an ASP.NET application while you make changes to it. This feature kicks in as soon as you place a file called app_offline.htm in the root of the application. When ASP.NET detects the file, it will shut-down the app-domain for the application and won’t restart it for requests. The app_offline.htm file will be sent as the response to all new dynamic requests for the application. When you’re done updating the site, just delete or rename the file and your site it will come back online.
Taken from (or actually inspired on) this blog post of Scott Guthrie:
Keep an eye on a feature of IE6(+) called “Show Friendly Http Errors”. This can be configured in the Tools -> Internet Options -> Advanced tab within IE, and is on by default with IE6. With this setting turned on, when a server returns a non HTTP-200 status code with less than 512 bytes of content, IE will not show the returned HTML and instead substitutes its own generic status code message.
If you use the app_offline.htm feature, make sure you have at least 512 bytes of content within it to make sure that your HTML shows up to your users instead of IE’s friendly status message. If you don’t want to have a lot of text show-up on the page, one trick you can use is to just add an html client-side comment with some bogus content to push it over 512 bytes. For example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" >
<head>
<title>Site Under Construction </title>
</head>
<body>
<h1>Under Construction </h1>
<h2>We're currently working on our site... </h2>
<!--
Adding additional hidden content so that IE Friendly Errors don't prevent
this message from displaying (note: it will show a "friendly" 404
error if the content isn't of a certain size).
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
<h2>Gone to Florida for the sun... </h2>
-->
</body>
</html>
Hope this helps