Click here to Skip to main content
15,879,096 members
Articles / Web Development / ASP.NET
Article

Putting ASP.net Application In Offline Mode Using app_offline.htm

Rate me:
Please Sign up or sign in to vote.
4.71/5 (16 votes)
15 Nov 2007CPOL3 min read 79.3K   30   4
Explanation of the use of undocumented app_offline.htm file in asp.net.

Introduction

ASP.net has a feature that makes an application in the offline mode. In offline mode, ASP.net does not serve any request made to the application. Instead it returned an error message, which can be customized, to the user. This feature uses a file called app_offline.htm.

app_offline.htm File

When ASP.Net found a file names app_offlinne.htm in the root of a web application directory, it shut-down the application, unload the application domain from the server, and stop processing any new incoming requests for that application. ASP.NET also then respond to all requests for dynamic pages in the application by sending back the content of the app_offline.htm file. The default content is an error message

'The application is currently offline. Remove app_offline.htm file from applications root directory.'

Visual Studio 2005 And app_offline.htm

SQL Server 2005 express edition does not support multiple processes. Only single process can access database at a time. So when a database is accessed through visual studio, ASP.net runtime cannot access the database. This will result into the internal server error. To prevent this, VS 2005 places app_offline.htm file in the application's root directory. The file contain above message. This causes ASP.net to put the application in offline mode. Please note the accessing database means opening any component of the database (I.e. table, view, stored procedure etc.) into the design window. When design window is closed, VS 2005 removes app_offline.htm file making the application in onliner mode again.

Using app_offline.htm As A Feature

You may use app_offline.htm feature to put your application in offline mope for any purpose. 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.

You should 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. When this is on, and 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.

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.

Once you remove the app_offline.htm file, the next request to the application will cause ASP.NET to load the application and app-domain again, and life will continue along as normal.

References

  1. Andy Gray wrote an interesting story on how his application stops working and starts giving error 404 when he killed visual studio process.
  2. Phill Scott writes his experience about suddenly getting error 404 and finding the app_offline.htm file culprit.
  3. Chris Ullman , author of Beginning ASP.NET 2.0 also had similar experience.
  4. Microsoft's ScottGu's Weblog.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager
United States United States
Delivery Manager by profession, Programmer and Architect by passion, Traveler and Nature Lover by hobby. Google me and you will find more about me.

Comments and Discussions

 
GeneralFavorites Pin
Johan Fourie20-Nov-07 11:50
Johan Fourie20-Nov-07 11:50 
GeneralFor naive users Pin
Imran Ullah Khan15-Nov-07 17:25
Imran Ullah Khan15-Nov-07 17:25 
GeneralUseful Pin
ajayshan15-Nov-07 16:53
ajayshan15-Nov-07 16:53 
GeneralSimple but useful Pin
canozurdo15-Nov-07 10:00
canozurdo15-Nov-07 10:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.