Thursday, April 24, 2014

App_Offline.htm feature in ASP.NET 2.0

"App_Offline.htm" feature in ASP.NET 2.0 provides a super convenient way to bring down an ASP.NET application while you make changes to it (for example: updating a lot of content or making big changes to the site where you want to ensure that no users are accessing the application until all changes are done).
  • This is very handy when we do deployments manually.
  • This allows you to remove the locks from those files and replace them, without the need to do a full IISRESET, taking down other sites on the server


How this is implemented?

We just need to put App_Offline.htmfile in root directory of web application and the ASP.NET runtime will detect the existence of  App_Offline.htm, if it exists, then the ASP.NET runtime will shut-down the application, unload the application domain from the server, and stop processing any new incoming requests for that application.

When all Web site files have been copied, you can delete the App_offline.htm. Once removed, the next request into the application will cause ASP.NET to load the application and app-domain again, and all things will continue to work as normal.

Important points to be considered while implementing “App_offline.htm”

Ø  Be sure that you are actually placing the "app_offline.htm" file in the "root" of the website that you have configured within IIS.

Ø  Also ensure that the file is named exactly as it should be. "app_offline.htm" 


  So if you use the app_offline.htm feature, you should make sure you have at least 512 bytes of content within it to make sure that your HTML (instead of IE's friendly status message) shows up to your users.  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:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Site Under Construction</title>
</head>
<body>
    <h1>
Under Construction</h1>
<h2>
Gone to Florida for the sun...</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>




No comments:

Post a Comment