Creating Custom ASP Error Pages

Article translations Article translations
Article ID: 224070 - View products that this article applies to.
This article was previously published under Q224070
Expand all | Collapse all

SUMMARY

Microsoft Internet Information Services (IIS) version 5.0 introduces the ability to create custom Active Server Pages (ASP) error pages through the addition of a new method for the built-in ASP Server object called Server.GetLastError() that returns a new ASPError object.

MORE INFORMATION

When an error occurs while you compile or run an ASP page, IIS generates a 500;100 error and executes a Server.Transfer() method to pass control to the currently defined custom error page. (By default this page is /iishelp/common/500-100.asp.) For more information on the Server.Transfer() method, see the following article in the Microsoft Knowledge Base:
219294 How to Use the Server.Transfer Method
When control is passed to the custom error page, the Server.GetLastError() method can be used to obtain detailed information regarding the error that occurred. The Server.GetLastError() method returns an ASPError object that has the properties listed in the following table. (This table can also be found in the IIS 5.0 online documentation.)
Collapse this tableExpand this table
PropertyDescription
ASPCodeReturns an error code generated by IIS.
NumberReturns the standard COM error code.
SourceIndicates if the source of the error was internal to ASP, the scripting language, or an object.
FileIndicates the name of the .asp file that was being processed when the error occurred.
LineIndicates the line within the .asp file that generated the error.
DescriptionReturns a short description of the error.
ASPDescriptionReturns a more detailed description of the error if it is an ASP-related error.
The steps listed below will walk you through setting up a custom ASP error page.
  1. Save the following ASP code in your Scripts folder as "My500.asp" (without the quotation marks):
    <%@Language="VBSCRIPT"%>
    <%
      Option Explicit
      On Error Resume Next
      Response.Clear
      Dim objError
      Set objError = Server.GetLastError()
    %>
    <html>
    <head>
    <title>ASP 500 Error</title>
    <style>
    BODY  { FONT-FAMILY: Arial; FONT-SIZE: 10pt;
            BACKGROUND: #ffffff; COLOR: #000000;
            MARGIN: 15px; }
    H2    { FONT-SIZE: 16pt; COLOR: #ff0000; }
    TABLE { BACKGROUND: #000000; PADDING: 5px; }
    TH    { BACKGROUND: #0000ff; COLOR: #ffffff; }
    TR    { BACKGROUND: #cccccc; COLOR: #000000; }
    </style>
    </head>
    <body>
    
    <h2 align="center">ASP 500 Error</h2>
    
    <p align="center">An error occurred processing the page you requested.<br>
    Please see the details below for more information.</p>
    
    <div align="center"><center>
    
    <table>
    <% If Len(CStr(objError.ASPCode)) > 0 Then %>
      <tr>
        <th nowrap align="left" valign="top">IIS Error Number</th>
        <td align="left" valign="top"><%=objError.ASPCode%></td>
      </tr>
    <% End If %>
    <% If Len(CStr(objError.Number)) > 0 Then %>
      <tr>
        <th nowrap align="left" valign="top">COM Error Number</th>
        <td align="left" valign="top"><%=objError.Number%>
        <%=" (0x" & Hex(objError.Number) & ")"%></td>
      </tr>
    <% End If %>
    <% If Len(CStr(objError.Source)) > 0 Then %>
      <tr>
        <th nowrap align="left" valign="top">Error Source</th>
        <td align="left" valign="top"><%=objError.Source%></td>
      </tr>
    <% End If %>
    <% If Len(CStr(objError.File)) > 0 Then %>
      <tr>
        <th nowrap align="left" valign="top">File Name</th>
        <td align="left" valign="top"><%=objError.File%></td>
      </tr>
    <% End If %>
    <% If Len(CStr(objError.Line)) > 0 Then %>
      <tr>
        <th nowrap align="left" valign="top">Line Number</th>
        <td align="left" valign="top"><%=objError.Line%></td>
      </tr>
    <% End If %>
    <% If Len(CStr(objError.Description)) > 0 Then %>
      <tr>
        <th nowrap align="left" valign="top">Brief Description</th>
        <td align="left" valign="top"><%=objError.Description%></td>
      </tr>
    <% End If %>
    <% If Len(CStr(objError.ASPDescription)) > 0 Then %>
      <tr>
        <th nowrap align="left" valign="top">Full Description</th>
        <td align="left" valign="top"><%=objError.ASPDescription%></td>
      </tr>
    <% End If %>
    </table>
    
    </center></div>
    
    </body>
    </html>
    						
  2. Set the custom ASP error page:

    1. Open the Internet Services Manager in the MMC.
    2. Expand your Default Web Site.
    3. Right-click on the Scripts folder and select Properties.
    4. Click the Custom Errors tab.
    5. Scroll down and highlight the 500;100 HTTP error and click Edit Properties.
    6. Ensure that Message Type is set to URL.
    7. Change the URL to "/scripts/my500.asp" (without the quotation marks).
    8. Click OK until you return to the MMC.
  3. Test the new error page:

    1. Save all of the following pages in your Scripts folder:

      • Save the following page as "Badpage1.asp" (without the quotation marks):
        <%@Language="VBSCRIPT"%>
        <html>
        <head>
        <title>Bad Page 1</title>
        </head>
        <body>
        <% Response.Write 1/0 %>
        </body>
        </html>
        										
      • Save the following page as Badpage2.asp" (without the quotation marks):
        <%@Language="VBSCRIPT"%>
        <html>
        <head>
        <title>Bad Page 2</title>
        </head>
        <body>
        <% Response.BadMethod "Hello" %>
        </body>
        </html>
        										
      • Save the following page as "Badpage3.asp" (without the quotation marks):
        <%@Language="VBSCRIPT"%>
        <html>
        <head>
        <title>Bad Page 3</title>
        </head>
        <body>
        <%
          Dim objBad
          Set objBad = Server.CreateObject("BAD.OBJECT.CLASS")
        %>
        </body>
        </html>
        										
    2. When you browse any of the above pages, you should now see the custom error page returned to the browser.
NOTE: When using Internet Explorer 5.0 and later to view Custom ASP Error Pages, unexpected results might be returned. IE5 introduced a feature to replace the HTML template for HTTP 500, and several other commonly returned status codes, with standardized, non-specific messages. To bypass this feature and show the exact text of the status code returned to the browser, open Internet Explorer and navigate to:
Tools | Internet Options | Advanced
					

then uncheck the checkbox labeled
Show friendly HTTP error messages
					

Additional information on this feature is available in
218155 Description of Hypertext Transport Protocol Error Messages

Properties

Article ID: 224070 - Last Review: November 21, 2006 - Revision: 1.2
APPLIES TO
  • Microsoft Internet Information Services 5.0
Keywords: 
kbaspobj kbcodesnippet kbinfo KB224070
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com