Export (0) Print
Expand All

Server.GetLastError Method

IIS 6.0

The GetLastError method returns an ASPError Object describing the error condition that occurred. This method is available only before the .asp file has sent any content to the client.

GetLastError(
)

This method has no parameters.

The following code example shows a page that you can configure as your default ASP error handling page for a web site.

NoteNote:

For more information about how to configure a custom ASP error page, see the Enabling ASP Error Processing topic.

<%@Language="VBSCRIPT"%>
<%
  Option Explicit
  On Error Resume Next
  Response.Clear
  Dim objError
  Set objError = Server.GetLastError()
%>
<html>
<head>
<title>ASP 500 Error</title>
</head>
<body>

<h2 align="center">ASP 500 Error</h2>

<p align="center">An error occurred processing the page that you requested.<br>
Please see the error 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>

The following three examples demonstrate different errors that generate a 500;100 custom error. The three types of errors are:

  • Preprocessing errors

  • Script compiling errors

  • Run-time errors

The following example demonstrates a preprocessing error, which IIS generates when it tries to include the file. This error will be generated because the #include statement is missing the file parameter for the #include statement.


<!--#include fil=inc.h  --> 
<% 
  response.write "hello" 
%> 

The following example demonstrates a script compiling error. The scripting engine does not compile this script because it is missing the keyword next in a For...Next loop.


<% 
  dim I 
  for i=1 to 1 
  nxt 
%> 

The following example demonstrates a run-time error that occurs because the script attempts to divide by 0.


<% 
  dim i,j 
  dim sum 
  sum=0 
  j=0 
  for i=1 to 10 
    sum=sum+1 
  next 
  sum=sum/j 
%> 

Applies To

If a 500;100 custom error has been defined for an ASP application, it may refer to an .asp file. In this case, when an error occurs during the running of an .asp file within the application, the server automatically transfers to this ASP page via the Server.Transfer method. All of the state information from the executing ASP application will be available to the .asp file that is handling the error. In addition, the ASPError Object will be available, so you can expose the properties of the error through the .asp file that you set up to handle the error.

The default Web site is configured to use the file \iishelp\common\500-100.asp. You can either use this file for processing ASP errors, or create your own. If you want to change the .asp file for processing the 500;100 custom errors you can use IIS Manager.

NoteNote:

A 500;100 custom error will be generated if IIS encounters an error while processing either an .asp file or the application's Global.asa file.

Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.

Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

Product: IIS

Show:
© 2014 Microsoft