22

I am following Scott gu's trick of placing a App_Offline.htm page at the route of my application to bring it offline - http://weblogs.asp.net/scottgu/archive/2006/04/09/442332.aspx

It does not seem to be working on one of my sites though. I place the file in IIS7 of one my sites, and all traffic is redirected to it.

However in the other site, same server etc, I get a page that contains "The service is unavailable.".

Not sure where I am going wrong - any ideas?

amateur
  • 43,371
  • 65
  • 192
  • 320

6 Answers6

22

I managed to solve it by putting the following code in my web.config:

<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />

        <defaultDocument>
            <files>
                <clear />
                <add value="index.html" />
                <add value="app_offline.htm" />
            </files>
        </defaultDocument>

        <httpErrors errorMode="Custom" existingResponse="Replace">
            <clear />
            <error statusCode="503" path="App_Offline.htm" responseMode="File" />
        </httpErrors>
    </system.webServer>
</configuration>

This fix was found by putting together some info from Scott Gu, npiaseck @ IIS Forum and Kurt Schindler.

demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
  • 5
    The critical bit for me only seemed to be that I was missing the line inside httpErrors for the 503 response code. The other changes do not seem to be necessary. – NickG Mar 12 '15 at 11:45
  • 1
    Yep the `` change for the 503 was all I needed too. – Will Appleby Mar 09 '18 at 20:18
  • 4
    There's nothing like Googling a problem and finding a StackOverflow answer that links to a solution you posted six years earlier because you apparently had this problem before and forgot you had it and how you solved it ;) – Nicholas Piasecki May 19 '18 at 12:07
12

this was my soluton - notice the 503...

    <httpErrors existingResponse="Replace" errorMode="Custom">
  <remove statusCode="404" subStatusCode='-1' />
  <remove statusCode="400" subStatusCode='-1' />
  <remove statusCode="500" subStatusCode='-1' />
  <remove statusCode="503" subStatusCode='-1' />
  <error statusCode="404" path="404.html" prefixLanguageFilePath="" responseMode="File" />
  <error statusCode="400" path="404.html" prefixLanguageFilePath="" responseMode="File" />
  <error statusCode="500" path="500.html" prefixLanguageFilePath="" responseMode="File" />
  <error statusCode="503" path="app_offline.htm" responseMode="File" />

</httpErrors>
JGilmartin
  • 8,683
  • 14
  • 66
  • 85
2

I had this issue with a MVC site recently, and I managed to solve it by replacing the web.config I originally had with a clean, minimal one when wanting to use the app_offline.htm file.

<?xml version="1.0"?>
<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
</configuration>

If I had more time I'd go through and find the exact thing in the web.config that was altering the behaviour, but this is worth a shot.

Henry C
  • 4,781
  • 4
  • 43
  • 83
2

I had the same problem recently when adding a app_offline.htm page to one of my sites.

All the answers here suggest to set the 503 response to the same app_offline.htm, I already have a different 503 page and don't really want to fiddle with that.

Also, I liked to know why this is happening.

The 503 is sent by the AspNetInitializationExceptionModule, I assume if the asp.net runtime detects the app_offline.htm file in the root of the web site, it sends an

503 Service Unavailable

and also does send the content of the app_offline.htm as a response.

However, because it is an error response the IIS error handing kicks in:

<httpErrors existingResponse="Replace">

The Replace here means, ignore whatever ASP.NET sent you and use your own 503 response. By specifying the same page (app_offline.htm) like suggested in the other answers this fixes the problem.

Another way to fix this is to change the existingResponse attribute, like:

<httpErrors existingResponse="Auto">

now IIS honours the response from ASP.NET and shows the content of the app_offline.htm file.

But Auto also means that other ASP.NET error responses may pass through.

Peter Hahndorf
  • 10,767
  • 4
  • 42
  • 58
1

Here's how you do it using the GUI (note the last line - that's the one you should add/edit)

enter image description here

Alex from Jitbit
  • 53,710
  • 19
  • 160
  • 149
0

All you need to do is rename your web.config to something else like web.config.bak while using the app_offline.htm.

tkc8800
  • 11
  • 1