Erik Porter's Blog

Life and Development at Microsoft and Other Technology Discussions

News

    Take Your ASP.NET 2.0 App Offline

    I just learned this a few minutes ago, but you can take an ASP.NET 2.0 application offline temporarily by uploading a file called App_Offline.htm.  It will spin down the appdomain and redirect all requests to that page.  Neato!

    Comments

    Ron Krauter said:

    Oh the coolness... Thanks!
    # October 5, 2005 10:52 PM

    Scott McCulloch said:

    Do you also need to set in the <httpRuntime> tag the attribute of enabled="false", this is what takes it down from the admin interface I think..
    # October 5, 2005 11:32 PM

    Jason Hoekstra said:

    Ahhh... the simple things in life really make me happy.
    # October 5, 2005 11:52 PM

    Bilal Haidar [MVP] said:

    Hi Erik:
    I tried to put such a page in the root directory of "File System" website and when I run the page, it will give me:
    "The page cannot be found",
    When i remove that page it works just fine and goes to my pages, is there any configuration that should be done? Does it work with File System websites or just http websites ?

    Regards'
    # October 7, 2005 3:40 AM

    Erik Porter said:

    Bilal, I don't know the answer for sure on that, but I believe that is correct. My question to you would be, why would you want to do this on a file system project on your local machine anyway. This feature is for your deployed application.
    # October 7, 2005 11:47 AM

    MaheshKumar.R said:

    Really awesome..it reduced my burden a lot..Thanks Guru :)
    Mahes,BLR,India
    # October 9, 2005 12:36 PM

    Sunish Abraham said:

    Hi Erik,

    Thanks for the information...I tried it out and it worked great! A colleague of mine tried this as well and somehome received a 404 (the App_offline.htm file was not empty)...so I wanted to make sure that this method was fool-proof. So I created a console application which used System.Net.WebRequest to access the website and flip-flop the App_offline.htm...it seems that I am receiving a 404 when I access the site programatically when the App_offline.htm exists. I would think I would have received a response which is similar to what I see in IE? Thanks for your assistance!

    Sunish
    # October 10, 2005 2:38 PM

    Danny said:

    hey how you turn online the aplication if in the asp.net web site admin tool u set "take application offline" by mistake

    i try to open up the asp.net web admin tool again but it shows me The resource cannot be found.
    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

    and now every asp.net site is down.

    # October 11, 2005 4:07 AM

    Scott D. said:

    Is this only with the 2.0.50727 build and above? I tried it on our QA servers running 2.0.50215 and also received HTTP 404.
    # October 11, 2005 12:55 PM

    Scott McCulloch said:

    Danny, open up web.config and set enabled=true in the httpRuntime tag
    # October 14, 2005 7:53 AM

    Vineeth Raja said:

    Thanks for the neat tip.
    # October 14, 2005 11:38 AM

    Vista Discuss said:

    That works! Awesome.
    # November 6, 2006 1:17 AM

    Pravesh Khadka said:

    Ah ! This is what I am looking for. It will save me time and energy to create whole different aspx file and put logic on it.

    Appreciated,

    Pravesh

    # December 1, 2006 1:39 PM

    Matt said:

    I just put the following into my app_offline.htm file and I stopped getting the resource not found error.

    <html>

    <head>

    </head>

    <body>

    We are currently down for maintenance.

    </body>

    </html>

    # December 6, 2007 2:02 PM

    Rob Thornley said:

    If you get a 404 error, then pad your app_offline file with comments.  I think once it exceeds something like 512 bytes it starts working

    # March 11, 2008 7:14 AM

    crow12 said:

    si pero como podria ejecutar toda una aplicacion offline sin estar conectado a mi servidor y en un momento dado todos lo que realiza en mi aplicacion pueda actualizarse con lo que tengo en mi servidor

    # April 15, 2008 6:04 PM

    jaybz said:

    actually, it depends on what browser is used as well.  1k most like is more than enough for most browsers.  here's what really happens in the background:

    if App_Offline.htm exists, IIS sends a 404 HTTP error result in the HTTP headers.  if the file is empty, IIS generates its own error content.  if it isn't, IIS sends the contents of App_Offline.htm.

    however, Google Chrome only displays the content if the server sends at least 512 bytes of content, otherwise it displays its own 404 error page.  Chrome is based on Apple's WebToolkit so Apple's Safari may exhibit the same behavior.

    IE7 has a similar behavior if you have "friendly HTTP errors" enabled, except, that the content needs to be more than 512 bytes long before IE7 decides to display it.  If you have it disabled, however, the content is displayed regardless of how long the content is.  The difference there is that if the content is exactly 512 bytes Chrome will display the content, IE7 will not.

    Firefox 3, always shows the content but may have a setting or a plugin that enables "friendly HTTP errors".

    i don't have any information regarding other browsers as I don't have them available at the moment.  i also cannot test 404 errors with no content because can't generate those yet.  for all intents and purposes, however, 1K should be more than enough to get the content displayed instead of the browsers' generic 404 page, if any.

    # September 17, 2008 4:08 AM

    acl123 said:

    I found that I had to make sure a .NET aspx page and a web.config file were present in the same directory as the App_Offline.htm file, or it wouldn't work.

    # October 21, 2008 11:10 PM