amateur
amateur

Reputation: 44673

app_offline site returning "The service is unavailable."

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?

Upvotes: 24

Views: 9977

Answers (6)

tkc8800
tkc8800

Reputation: 11

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

Upvotes: 0

Peter Hahndorf
Peter Hahndorf

Reputation: 11222

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.

Upvotes: 2

Alex from Jitbit
Alex from Jitbit

Reputation: 60922

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

Upvotes: 1

Henry C
Henry C

Reputation: 4801

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.

Upvotes: 2

JGilmartin
JGilmartin

Reputation: 9308

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>

Upvotes: 13

demoncodemonkey
demoncodemonkey

Reputation: 11957

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.

Upvotes: 23

Related Questions