P. 1
Debug ASP

Debug ASP

|Views: 228|Likes:
Published by Raghunath Chandran

More info:

Published by: Raghunath Chandran on Aug 08, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/20/2012

pdf

text

original

Although a variety of new debugging features in the Visual Studio .NET IDE can be
used in debugging your ASP.NET applications, some old methods and tricks from
the days of ASP are still worthwhile.

Using the Response Object

Previous versions of ASP are built on the foundation of five objects: Response,
Request, Server, Application, and Session. The Response object is used to send
information from the server down to the client’s browser. The Write method of the
Response object can be used to dynamically write content to the client’s browser.
This is one of the easiest ways to debug standard ASP pages and is still applicable in
the new architecture.

The problem with this approach is that it isn’t very pretty. At the end of debugging
a long logic process, you will wind up with a pile of if/then statements and
Response.Write() calls littered throughout your .asp pages. This output can get
lost inside the HTML if it’s not placed properly. A better approach is to create a
specific debugging object that outputs important and pertinent information but
handles it in a much nicer and cleaner fashion.You will write an object like this later
in the chapter so that you can use it very easily in your ASP debugging procedures.

Using the Server Object

Internet Information Server (IIS) 5.0 included a new method on the Server object,
called GetLastError. This method returns an ASPError object that contains almost
everything you need to know about the error except how to correct it. Table 2.1
shows what properties are available on the ASPError object.

Table 2.1. Properties of the ASPError Object

ASP Code

Error Code from IIS

Number

COM error code

Source

Source of line that caused error

Category

Type of error (ASP, script, object)

New Riders - Debugging ASP.NET made by dotneter@teamfly

File

ASP file where error occurred

Line

Line number where error occurred

Column

Column where error occurred

Description

A text description of the error

ASPDescription

Detailed description if error was ASP-related

You will notice that the information returned in the object is the same information
that is presented to you in a standard ASP error page. However, with this
information at your disposal, you can create a custom error page that is displayed
instead of the standard ASP error page.You can set the error to your own custom
page by using the IIS Admin tool. If a custom page is selected, then when the server
encounters an error, it will perform a Server.Transfer to the error page,
maintaining all state information to the new page. This enables you to get an
instance of the ASPError object and pull out the pertinent information for display as
a debugging guide. Listing 2.3 shows such a page.

Listing 2.3 Sample ASP Error Page Using the ASPError Object

<%

Dim Err
Set Err = Server.GetLastError()

%>


Error

An error has occurred!









New Riders - Debugging ASP.NET made by dotneter@teamfly









Description <%=Err.Description%>
Number <%=Err.Number%>
Category <%=Err.Category%>
File <%=Err.File%><
Line <%=Err.Line%><;/td>

Column <%=Err.Column%>
Source <%=Err.Source%>
ASP Description <%=Err.ASPDescription%>



<% Set Err = Nothing%>

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->