Creating Custom ASP Error Pages

ID: Q224070


The information in this article applies to:
  • Microsoft Internet Information Services version 5.0


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:

Q219294 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.)
Property Description
ASPCode Returns an error code generated by IIS.
Number Returns the standard COM error code.
Source Indicates if the source of the error was internal to ASP, the scripting language, or an object.
File Indicates the name of the .asp file that was being processed when the error occurred.
Line Indicates the line within the .asp file that generated the error.
Description Returns a short description of the error.
ASPDescription Returns 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.


Additional query words: iis

Keywords :
Version : winnt:5.0
Platform : winnt
Issue type : kbinfo


Last Reviewed: February 2, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.