Best Way To Debug ASP Pages

M

Matthew Louden

I want to know what's the best way to debug ASP pages? Now, I just put the
following code when I got run-time error, but sounds like not efficient.
Please advice! Thanks!

Response.Write "Here"
Response.End
 
P

PB4FUN

1. Visual Interdev
Real debugging like in Visual Basic : line by line,
asking values of variables, set a watch, change variables in runtime
etc.
2. On top of page ad On Error Resume Next
After each line of code use
If Err.Number <> 0 Then
Response.Write Err.Description
Err.Clear
End if
You might also Set a Debuggingvariable e.g. intDebug that you increase every
x lines
intDebug = intDebug + 1

If Err.Number <> 0 Then
Response.Write intDebug
response.Write "<BR>"
Response.Write Err.Description
Err.Clear
End if

But first option (Visual Interdev) is the best IF you get it working.

Meindert, MCP
 
C

Chris Barber

See the following for details of how to set it up (Visual Interdev
Debugging).

http://www.windowswebsolutions.com/Articles/Index.cfm?ArticleID=20431

http://www.microsoft.com/mind/0299/beyond/beyond0299.asp

Chris.

1. Visual Interdev
Real debugging like in Visual Basic : line by line,
asking values of variables, set a watch, change variables in runtime
etc.
2. On top of page ad On Error Resume Next
After each line of code use
If Err.Number <> 0 Then
Response.Write Err.Description
Err.Clear
End if
You might also Set a Debuggingvariable e.g. intDebug that you increase every
x lines
intDebug = intDebug + 1

If Err.Number <> 0 Then
Response.Write intDebug
response.Write "<BR>"
Response.Write Err.Description
Err.Clear
End if

But first option (Visual Interdev) is the best IF you get it working.

Meindert, MCP
 
C

C. Olive

PB4FUN said:
1. Visual Interdev
Real debugging like in Visual Basic : line by line,
asking values of variables, set a watch, change variables in runtime
etc.
2. On top of page ad On Error Resume Next
After each line of code use
If Err.Number <> 0 Then
Response.Write Err.Description
Err.Clear
End if
You might also Set a Debuggingvariable e.g. intDebug that you increase every
x lines
intDebug = intDebug + 1

If Err.Number <> 0 Then
Response.Write intDebug
response.Write "<BR>"
Response.Write Err.Description
Err.Clear
End if

But first option (Visual Interdev) is the best IF you get it working.

Meindert, MCP

Another useful method I've used on any server, not just IIS, is
writing HTML comments to the client. Then use "View Source" to see
the comments sprinkled along with the actual visible markup. Under
IIS, an ASP subroutine like this works great:

Sub Debug( strMsg )

Response.Write "<!-- " & strMsg & " -->" & vbCRLF

End Sub

....then in code...

While Not RS.EOF
Response.Write "<td>" & RS.Name & "</td>"
Debug RS.Address 'Not sure what to do with this yet
Debug RS.City 'Is this coming out right?
Debug RS.State 'etc.
Loop

Chris
 
J

J. Spraul

IIS v5+ has an exponential increase in error-handling
support. I guess if you're talking about debugging
during development, then this may not be as much
of an interest to you, but you can read more here...

http://www.devarticles.com/art/1/382

If you don't have Visual Interdev + IIS installed on
your development machine then you won't be able to
step through your ASP (and some people still can't
even when they do have both installed - it's a
royal pain to get working). Here's that info...

http://support.microsoft.com/support/kb/articles/Q244/2/72.ASP

If you want, you can use a subroutine to make it
a little easier (it's been a while since I've done
this, but I think it will work). Just put the main
logic of your code in a subroutine, like this...

SUB Main()
'do your stuff here...

END SUB

' this is the only non-subroutined ASP on the page...
ON ERROR RESUME NEXT
CALL Main
IF Err.Number THEN Response.Write Err.Description


You can switch to Server.GetLastError() if you're
using IIS 5/ASP 3 so you can get more info, like
the line that the error occurred on. If you didn't
mind using this same approach in production, you
could stick the part the calls Main in an include
and have a SUB Main in every ASP file which pulls
in the include... then you can switch between
debugging & "notify me when something wrong happens
because it should work" modes. Here is some info
specifically on the GetLastError/ASPError stuff...

http://www.devguru.com/Technologies/asp/quickref/asperror.html

~jed
 
B

Bullschmidt

Of course Response.Write's are a good way to do some debugging.

For example in a login page where the user's access level is assigned to
a session variable one could do something like the following:
Response.Write objRST("UserName") & "<br>"
Response.Write objRST("UserPassword") & "<br>"
Response.Write objRST("UserAccess") & "<br>"
Response.Flush
Response.End

The second of the last line above is often required if buffering is set
on (Response.Buffer = True) which it perhaps usually would be.
The last line above is optional for if you need to stop the code from
running after that point (i.e. to avoid a page redirect or something).

Debugging your ASP Scripts by Abd Shomad - 2/10/1999
http://www.4guysfromrolla.com/webtech/021099-1.shtml

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top