Microsoft KB Archive/224070

= Creating Custom ASP Error Pages =

Article ID: 224070

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q224070



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.)

The steps listed below will walk you through setting up a custom ASP error page.   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 %> ASP 500 Error 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; }

ASP 500 Error

An error occurred processing the page you requested. Please see the details below for more information.

 Set the custom ASP error page:

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

<ol style="list-style-type: lower-alpha;"> Save all of the following pages in your Scripts folder:

<ul>  Save the following page as "Badpage1.asp" (without the quotation marks):

<%@Language="VBSCRIPT"%> Bad Page 1 <% Response.Write 1/0 %> </li>  Save the following page as Badpage2.asp" (without the quotation marks): <%@Language="VBSCRIPT"%> Bad Page 2 <% Response.BadMethod "Hello" %>                                        </li>  Save the following page as "Badpage3.asp" (without the quotation marks):  <%@Language="VBSCRIPT"%> Bad Page 3 <%  Dim objBad  Set objBad = Server.CreateObject("BAD.OBJECT.CLASS") %>                                        </li></ul> </li> When you browse any of the above pages, you should now see the custom error page returned to the browser.</li></ol> </li></ol>

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:

<pre class="fixed_text">Tools | Internet Options | Advanced

then uncheck the checkbox labeled

<pre class="fixed_text">Show friendly HTTP error messages

Additional information on this feature is available in

218155 Description of Hypertext Transport Protocol Error Messages

Additional query words: iis

Keywords: kbinfo kbcodesnippet kbaspobj KB224070

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.