Published: Friday, August 17, 2001
Tracing in ASP
By Scott Mitchell
Introduction
In a previous article, Tracing in ASP.NET, I examined a neat, cool new
feature of ASP.NET - Tracing. In the article I mentioned classic ASP's lack of inherent tracing support,
requiring the developer to have to do with sloppy Response.Write statements to output the contents
of various variables throughout the page. In my article I pointed out a couple of disadvantages of relying on
the sloppy Response.Write statements, the most profound ones being:
- Before shipping an application, a developer must go through each ASP page and ensure that she's removed
all debugging
Response.Write statements.
- Using
Response.Write statements for debugging on a live Web site can lead to messy
Response.Write statements displayed on live Web pages, which is highly undersirable.
Over the course of the past two days I've gotten a number of feedback responses
from various 4Guys visitors who all acknowledged that, yes, tracing in ASP.NET is cool, but tracing in classic
ASP doesn't have to be as bad as I made it out. In this short article, I'm going to present some of the
more clever feedback responses I got from users who shared their techniques for making tracing in classic
ASP that much easier!
Turning Resposne.Write Tracing On and Off in One Location
I just read the Tracing in ASP.NET article posted to your
WebWeekly newsletter. I've
used a similar technique in classic ASP for quite a while now. I
typically create a GLOBAL.INC include file for each application. One of
the code snippets that I add to this file is a boolean variable called
blnDebug. Anytime I use a Response.Write throughout the app to print
debug information I preface it with If blnDebug Then Response.Write....
This way I can turn debugging on/off throughout the app simply by toggling
the single boolean variable. Of course, the include file must be set on each page. :-)
Thanks for the great websites!!!
From 4Guys visitor Blake C.
Displaying Response.Write Tracing Statements only for the Site's Developers
Hello! I have been enjoying and benefitting from the WebWeekly newsletter, and wanted to
offer some feedback/comments on this week's article Tracing in ASP.NET...
You mention that debugging in Classic ASP is usually handled via
Response.Writes scattered about the page, and that shortcomings with this
method are (a)you must remember to go through and remove them when
finished; and (b) on a live production server your visitors will see your
debugging comments.
While Tracing in ASP.NET seems like a nice feature, I have been using a
very simple solution in my Classic ASP pages that works quite well and
avoids the shortcomings you mentioned. I'm writing to share this with you
as your websites and articles have been invaluable to me in my
development. Instead of using Response.Write to output debugging information, I wrote a
simple function that only outputs debugging comments to me and only to me
(or to whomever I allow, determined by REMOTE_ADDR or even a session
variable that can be set on a special admin page.)
I call this function debug, and it's pretty straightforward, and has
been working like a charm for me...
<%
Function debug(str)
If Request.ServerVariables("REMOTE_ADDR") = "127.0.0.1" or _
Session("developer") = True Then
Response.Write str & "<br>" & vbCrLf
End If
End Function
%>
|
Thank you for the time, energy, and devotion you put into your work, and
thank you for sharing it with us all!
From avid 4Guys reader Michael Y.
Conclusion
There you have it, a couple of ways to ease using tracing in classic ASP. While these workarounds are great,
I think most will still agree that ASP.NET's tracing is easier to use than in classic ASP. In any case, many
thanks to all of those who sent in feedback!
Happy Programming!
By Scott Mitchell
Related Links:
Read Tracing in ASP.NET
Visit the ASP.NET Article Index