134

I've read about the app_offline.htm file which can be placed within the root of a .NET 2.0 application which will in essence shut down the application and disable any other pages from being requested.

I've placed the file in the root, and my site still loads. I went into default documents in IIS and set it to app_offline.htm and the site still loads (this might have been a caching issue though)

Anyway, has anyone run into issues using this? Am I doing something wrong?

Michał Powaga
  • 22,561
  • 8
  • 51
  • 62
Jack Marchetti
  • 15,536
  • 14
  • 81
  • 117
  • Is there a Microsoft page that documents this? – Paul C Nov 14 '14 at 15:55
  • http://blogs.msdn.com/b/amb/archive/2012/02/03/easiest-way-to-take-your-web-site-offline-iis-6-0-or-iis-7-5-with-net-4-0.aspx – Jack Marchetti Nov 15 '14 at 20:07
  • Official documentation: https://msdn.microsoft.com/en-us/library/ff925031.aspx – Brian Jan 31 '17 at 17:16
  • I have successfully used app_offline.htm to hide my web app content and display the temporary page. However I am having trouble reviewing the original data even after deleting the app_offline.htm file. Her's my question: http://stackoverflow.com/questions/42979042/web-app-displaying-app-offline-htm-content-even-after-removing-it-from-root-dire – naz786 Mar 23 '17 at 14:58

7 Answers7

170

I have used the extremely handy app_offline.htm trick to shut down/update sites in the past without any issues.

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

Other than that, there should be no other changes to IIS that you should need to make since the processing of this file (with this specific name) is handled by the ASP.NET runtime rather than IIS itself (for IIS v6).

Be aware, however, that although placing this file in the root of your site will force the application to "shut down" and display the content of the "app_offline.htm" file itself, any existing requests will still get the real website served up to them. Only new requests will get the app_offline.htm content.

If you're still having issues, try the following links for further info:

Scott Gu's App_Offline.htm

App_Offline.htm and working around the "IE Friendly Errors" feature

Will app_offline.htm stop current requests or just new requests?

Community
  • 1
  • 1
CraigTP
  • 44,143
  • 8
  • 72
  • 99
  • 6
    @JackM - No problem! In fact, I often leave the file on my website and call it something like "xapp_offline.htm". It therefore just sits there doing nothing. When I want to upgrade some or all of the site, I simply rename the file and remove the "x" prefix (this is usually done over FTP). This shuts down the site for me, I do the upgrade, then rename the file back with the "x" prefix! – CraigTP Jul 20 '09 at 19:20
  • @JackMarchetti - Will this also work for ASP.NET MVC websites that use global.asax routing? I've checked all of the suggestions here but still have no luck getting this to work :( – Squig Mar 18 '13 at 11:49
  • Update to previous comment: It's working now and must have been some kind of caching issue. I'd used +Refresh, but presumably it was being cached somewhere else. – Squig Mar 18 '13 at 12:23
  • Is there a Microsoft page that documents this? – Paul C Nov 14 '14 at 15:56
  • 1
    @CodeBlend Well, the link to ScottGu's blog is fairly official, but I suppose the most "official" Microsoft page would be this one on MSDN: http://msdn.microsoft.com/en-us/library/vstudio/ff925031(v=vs.100).aspx – CraigTP Nov 14 '14 at 16:05
  • To make this in effect, we need to refresh the page. I am using web api and angular. If we request to web api, I am getting this page in alert as html. Other js file are not called... – Jeeva J Feb 05 '16 at 10:42
  • Note. even extension is important! "app_offline.html" does not work. "app_offline.htm" works! – Mark May 09 '18 at 12:15
  • Yes, file name should be `app_offline.htm`. But it is **case insensitive** – Tanmay Nov 15 '18 at 15:45
48

Make sure your app_offline.htm file is at least 512 bytes long. A zero-byte app_offline.htm will have no effect.

UPDATE: Newer versions of ASP.NET/IIS may behave better than when I first wrote this.

UPDATE 2: If you are using ASP.NET MVC, add the following to web.config:

<?xml version="1.0"?>
<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
</configuration>
Mark Richman
  • 28,948
  • 25
  • 99
  • 159
  • 1
    I had the exact filename with an empty file and that worked - blank page displayed regardless of the url I used – Paul C Nov 14 '14 at 15:54
  • Check this link for the 512 byte limit issue: http://www.codeproject.com/Articles/21319/Putting-ASP-net-Application-In-Offline-Mode-Using – Masood Khaari Sep 26 '15 at 02:18
  • This is true especially for older versions of IE which can replace the page with it's own error message – ChewToy Apr 11 '16 at 10:10
  • Scott Gu describes it also in his [**blog.**](https://weblogs.asp.net/scottgu/App_5F00_Offline.htm-and-working-around-the-_2200_IE-Friendly-Errors_2200_-feature) – Matt May 12 '16 at 14:37
  • 2
    I could only get my MVC site to go into app offline mode by completely replacing my web.config with above – Matthew Lock Nov 01 '16 at 01:40
15

Note that this behaves the same on IIS 6 and 7.x, and .NET 2, 3, and 4.x.

Also note that when app_offline.htm is present, IIS will return this http status code:

HTTP/1.1 503 Service Unavailable

This is all by design. This allows your load balancer (or whatever) to see that the server is off line.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Jonesome Reinstate Monica
  • 6,618
  • 11
  • 65
  • 112
  • 1
    Surely you don't want your load balancer to think that the server is offline, because you want to display the `app_offline.htm` to users during your maintenance window? – Luke Aug 20 '17 at 10:08
  • 2
    @Luke: A better example of why a 503 response is helpful: It's preferable that Google's web crawler knows your website is currently down, rather than decided to index your "site is down" content (and flagging your site as having a ton of duplicate content). Also, it may be helpful if your CDN can detect that your origin is down and thus will avoid caching your content. – Brian Oct 27 '17 at 18:17
10

Possible Permission Issue

I know this post is fairly old, but I ran into a similar issue and my file was spelled correctly.

I originally created the app_offline.htm file in another location and then moved it to the root of my application. Because of my setup I then had a permissions issue.

The website acted as if it was not there. Creating the file within the root directory instead of moving it, fixed my problem. (Or you could just fix the permission in properties->security)

Hope it helps someone.

Jeremy A. West
  • 2,162
  • 4
  • 27
  • 40
4

Make sure that app_offline.htm is in the root of the virtual directory or website in IIS.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
4

Make sure filename extensions are visible in explorer and filename is actually

app_offline.htm

not

app_offline.htm.htm

nPcomp
  • 8,637
  • 2
  • 54
  • 49
1

I ran into an issue very similar to the original question that took me a little while to resolve.

Just incase anyone else is working on an MVC application and finds their way into this thread, make sure that you have a wildcard mapping to the appropriate .Net aspnet_isapi.dll defined. As soon as I did this, my app_offline.htm started behaving as expected.


IIS 6 Configuration Steps

On IIS Application Properties, select virtual Directory tab.

Under Application Settings, click the Configuration button.

Under Wildcard application maps, click the Insert button.

Enter C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll, click OK.

Peter Bernier
  • 8,038
  • 6
  • 38
  • 53