All about ASPError Object

 

ASP 3.0 has introduced a new object called ASPError, which offers better information for tackling errors than previous versions of ASP.

 

The ASP Error object provides a way to detailed display of any error that occurs when processing an ASP page.  The following code demonstrates how to obtain a reference to an ASPError object and use its properties to display an informative error message.  This page will be used as a custom error page that is executed automatically by ASP when an error occurs.  .

 

ASPError object properties

 

Number

Returns standard COM error code for the error occurred

Description

Returns a short text description of the error

Source

Returns the actual source code of the line where the error was detected

File

Returns the name of the file that was being processed when the error occurred

Line

Returns the number of the line within the file where the error was detected

Column

Returns a long integer value indicating the character position within a line of the file that generated the error

Category

Returns a string that indicates the source of the error, whether it was generated by ASP, by the scripting language, or by an external object

ASPCode

Returns a string which contains the error number that was generated by ASP or IIS

ASPDescription

Returns a string containing the detailed description of the error, if it is ASP related

 

A generic custom error page

 

<HTML>

<HEAD>

<TITLE>ASP Error</TITLE>

</HEAD>

<BODY>

<%

Set objASPError = Server.GetLastError()

 

IntNumber = objASPError.Number

strDesc = objASPError.Description

strSource = Server.HTMLEnode(objASPError.Source)

strFile = objASPError.File

IntLine = objASPError.Line

IntColumn = objASPError.Column

strCategory = objASPerror.Category

strASPCode = objASPError.ASPCode

strASPDesc = objASPError.ASPDescription

 

strMsg = "<H2>"& strCategory & "error "& intNumber & " </H2>"

strMsg = strMsg & strDesc & "<BR><B>"

strMsg = strMsg & strFile & "</B>"

 

If intLine > 0 Then

            strMsg = strMsg & ",  line " &  intLine

End If

 

'If it is not syntax error, the column will be  -1

If intColumn > 0 then

     strMsg = strMsg & ", column " &  intColumn

End If

strMsg = strMsg & "<BR>"

 

 

'The surce is only returned for compilation errors

If strSource <> ""  Then

            strMsg = strMsg & "<BR><FONT  FACE = 'courier' > " & strSource & "<BR>"

    For intCount = 1 To intColumn

            strMsg = strMsg & "-"

    Next

    strMsg = strMsg & "^</FONT><BR>"

End If

 

strMsg =strMsg & "<BR>"

 

‘ASP-specific errors provide additional information in the

‘ASPCode and ASPDescription properties

If strASPCode <> "" Then

    strMsg =strMsg & " ASPError: " & strASPCode & "." & strASPDesc

End If

 

Response.write strMsg

Set objASPError = Nothing

%>

</BODY>

</HTML>

 

Configuring Custom Error Pages

 

When an error on an ASP page and the page itself cannot be sent to browser, IIS sends a page containing information about the error instead.  This can be either and asp page or normal HTML page.  IIS is installed with the number of default error pages –the standard ASP Error messages you have probably encountered all too often during debugging-but we can actually instruct IIS to load any other page instead, these error pages are usually referred to as custom error pages. The default error pages supplied with IIS can be found in the WINNT\HELP\iishelp\common directory.  These pages can be opened in a browser just like any other web pages, or the source code can be viewed in a text editor.

 

Error Page mapping in IIS

 

When IIS detects an error, it sends an error page back to the client.  Because different error scan result in different error pages, IIS maps individual error types specific pages. We can alter these mappings on a directory - by  –directory or a file by – file basis.  To change the error page for a particular directory or web page, open up the custom error pages of the directory’s or file’s  properties dialog by right clicking on the directory or file in the internet services manager and selecting properties,  and then selecting custom errors tab.  This displays a list of the HTTP errors  to which we can map error pages, together with either the absolute URL or  the physical path of the page to which the error is currently mapped. Errors generated by ASP of type 500s, and as you can see,  some of these errors are already mapped to specific pages;

 

Select the entry for any error and click on the edit properties button. This will open the Error Mapping Properties dialog. Select URL as message type and type the full virtual path (minus domain name, but including preceding forward slash) to your own custom error page. Now this custom error page will be opened whenever that particular type of error occurs.

 

For further clarifications mail me at  Vegas_201@yahoo.com