Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
809 views
in Technique[技术] by (71.8m points)

asp.net - Custom Error Page for Http Error 503

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...