17

I need to send a Customized Error page for 503 Errors produced by my asp.net website. I have tried to simulate the condition by switching off the application pool (doesn't work) and by flooding my application with requests. Even though IIS sends me the default 503 error page, and even though I have tried setting a Custom URL in IIS and ASP.NET for this error code, it still returns me the default 503 error page !

I'd appreciate if someone could also tell me where the default 503 error page is kept that IIS sends.

Storm
  • 4,307
  • 11
  • 40
  • 57

4 Answers4

12

Ran into the same problems, but I've just managed to get this working for us using a Classic ASP holding page in a .NET application (I'm not sure if it'll work the same for an apsx):

  1. Make sure Classic ASP is enabled in IIS. Worth a read: http://blogs.iis.net/bills/archive/2007/05/21/tips-for-classic-asp-developers-on-iis7.aspx

  2. Create a classic ASP file called Offline.asp and place it in the root of your website with the following contents:

    <%
    
    Response.Status = "503 Service Unavailable"
    Response.CacheControl = "no-cache"
    Response.AddHeader "Pragma", "no-cache"
    Response.Expires = -1
    
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <meta name="robots" content="noindex,nofollow" />
            <title>Sorry, we're down for essential maintenance</title>
        </head>
        <body><h1>Sorry, we're down for essential maintenance</h1></body>
    </html>
    
  3. Now in IIS7 Manager go the Error Pages administration section, add a Custom Error Page like so:

    Error Pages

    Add Custom Error Page

    Error Pages

Now whenever IIS receives a 503, it will send the contents of the Offline.asp to the browser, as well as the 503 code (which is important so that Search Engines don't list your error page!)

Now if you want to take your application offline you can just set up a simple redirect rule to redirect everything to Offline.asp.

Chris Haines
  • 6,445
  • 5
  • 49
  • 62
  • I have just achieved the same thing with an aspx file. I put the server side code in the aspx file to keep things simple. – Brian Hinchey Jul 11 '11 at 06:06
  • 8
    This doesn't work when the app pool is stopped either. I'm not sure if it would work if the app pool was overloaded as it is hard to recreate that condition when you want it. – mike nelson Jul 27 '11 at 04:02
  • 1
    Does someone knows solution for mvc application? – Ashish Shukla Jul 03 '18 at 00:33
  • if you're intentionally stopping IIS, then you could have a console app serve a maintenance page on the web port while this is going on – Mr AH Apr 01 '20 at 11:33
  • If the app pool is stopped, you can serve a custom error 503 page by placing a file named [app_offline.htm](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/app-offline?view=aspnetcore-5.0) in the root directory of the app. – DecimalTurn Feb 05 '21 at 08:07
  • @RichardHsieh I posted this answer over 10 years ago... I'm not surprised it doesn't work for you! No need to downvote an answer that worked at the time though. – Chris Haines Jun 16 '21 at 10:37
  • I tried this way but failed, my web api returns 503 but the browser doesn't redirect to the customized 503 page, still popup our customized error dialog containing customized error message, I searched and found https://serverfault.com/questions/857268/show-customize-503-message-when-app-pool-is-stopped , and it links to https://learn.microsoft.com/en-us/iis/configuration/system.webserver/httperrors/error which says 503 can't be customized. – user1108069 Dec 22 '21 at 06:09
10

You cannot customise the default 503 Service Unavailable error message. This is returned typically when the app pool is unavailable for some reason.

This description of when it occurs states that it comes directly from http.sys and everything on the internet seems to concur that it cannot be changed. I've looked at the http.sys registry settings and theres nothing useful there.

http://technet.microsoft.com/en-us/library/cc781893(WS.10).aspx

mike nelson
  • 21,218
  • 14
  • 66
  • 75
  • 1
    https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc753103(v=ws.10) Indeed Microsoft said it cannot be customized. – Lex Li Jul 16 '18 at 13:02
  • What a shame. It would be nice if this was customizable. – Johnny Oshika Aug 06 '18 at 22:03
4

Take a look at HttpContext.Current.Response.TrySkipIisCustomErrors. just a suggestion.

Sky Sanders
  • 36,396
  • 8
  • 69
  • 90
  • Yes, i've tried this also. But this won't work when the app pool is switched off. – Storm Feb 16 '10 at 10:25
  • well, that is all i got for now. have less than zero desire to deal with IIS7 custom errors. I already fixed asp.net's 10 year old custom 403 error page bug once this year. http://www.codeproject.com/Articles/39062/Salient-Web-Security-AccessControlModule.aspx good luck.. – Sky Sanders Feb 16 '10 at 10:31
0

As far as i can see, error pages are kept under %SystemDrive%\inetpub\custerr\<LANGUAGE-TAG>\<HTTP-CODE>.htm

You can configure custom error pages per website in your iis7 mmc.


edit

Apperently there is no way past http.sys in case of 503 - the only choice you get, is to send the default http 503 error message or to terminate the connection on tcp level.

Filburt
  • 17,626
  • 12
  • 64
  • 115