When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Wednesday, February 10, 1999

Debugging your ASP Scripts
By Abd Shomad


Wouldn't it be nice if you could debug all of your scripts which use collections by writing a single line of code such as:

- continued -

<!--#include virtual="/include/DebugCollection.inc"-->

or

Call DebugCollection

When you are designing forms and collect it's fields value(s) to be processed on other page, you often mix up with the form input values. If you're smart enough, maybe you will send the form information to a "special debug page" containing special debugging script. But there's a better way to debug the form collection (and any other collection, off course):

- -- Write your debugging script on "special included file". -- -

First, you can save your time to *not to copy and paste* the debugging code on another page. Secondly, you may add new features to the debugging page once new features available.

If you see at the sample include file (see sample code below), I write the debugging code only for:

    - QueryString Collection
    - Form Collection
    - Cookies Collection
    - Server Variables Collection, and
    - ClientCertificate Collection

As IIS 4.0 released, Microsoft added new collections:

    - Session Variable Collection
    - Application Variable Collection
we can leverage the new capabilities into our debug page.

I save all the include files on special virtual directory named "/include". I name the file "collection.inc":

When we need to debug our form, querystring or any other collection, we need only to write (or copy and paste) the code below:

<!--#include virtual="/include/collection.inc"-->

and your debugging process getting very much easier than ever. And when you think that you no longer need to debug your form, just delete it.

Here is the included file at my "/include" virtual directory.


- --- FILE: "collection.inc" --- -
<% ' Purpose: Display all the application collections %>

<!-- Content -->

<!-- The Application and Session Variable collection is a new features of IIS 4.0 the code below was added since IIS 4.0 released --> <h3> Application Variable Collection </h3> <% On Error Resume Next For Each Item in Application.Contents Response.Write Item & " = " & Application.Contents(Item) & "<BR>" For Each ItemKey in Application.Contents(Item) Response.Write "Sub Item: " & Item & " (" & ItemKey & ") : " _ & Application.Contents(Item)(ItemKey) & "<br>" Next Next ' Key if err.no > 0 Then Display "You must upgrade to IIS 4.0 in order to use the Application Collection<br>" %>

<!-- All collections at the code below are available at IIS 3.0 --> <h3> Session Variable Collection </h3> <% On Error Resume Next For Each Item in Session.Contents Response.write Item & " = " & Session.Contents(Item) & "<BR>" For Each ItemKey in Session.Contents(Item) Response.Write "Sub Item: " & Item & " (" & ItemKey & ") : " _ & Session.Contents(Item)(ItemKey) & "<br>" Next Next if err.no > 0 Then Display "You must upgrade to IIS 4.0 in order to use the Session Collection<br>" %>

<h3> QueryString Collection </h3> <% For Each Item in Request.QueryString For iCount = 1 to Request.QueryString(Item).Count Response.Write Item & " = " & Request.QueryString(Item)(iCount) & "<br>" Next Next %>

<h3> Form Collection </h3> <% For Each Item in Request.Form For iCount = 1 to Request.Form(Item).Count Response.Write Item & " = " & Request.Form(Item)(iCount) & "<br>" Next Next %>

<h3> Cookies Collection </h3> <% For Each Item in Request.Cookies If Request.Cookies(Item).HasKeys Then 'use another For...Each to iterate all keys of dictionary For Each ItemKey in Request.Cookies(Item) Response.Write "Sub Item: " & Item & "(" & ItemKey & ")" Response.Write " = " & Request.Cookies(Item)(ItemKey) Next Else 'Print out the cookie string as normal Response.Write Item & " = " & Request.Cookies(Item) & "<br>" End If Next %>

<h3> ClientCertificate Collection </h3> <% For Each Item in Request.ClientCertificate For iCount = 1 to Request.ClientCertificate(Item).Count Response.Write Item & " = " & Request.ClientCertificate(Item)(iCount) _ & "<br>" Next Next %>

<h3> ServerVariables Collection </h3> <% For Each Item in Request.ServerVariables For iCount = 1 to Request.ServerVariables(Item).Count Response.Write Item & " = " & Request.ServerVariables(Item)(iCount) _ & "<br>" Next Next %> <p><font SIZE="2"><cite>Modified code from Wrox Press Limited</cite></font>

If you think that you will always use this debugging script and you want to call the debugging process by only typing

Call DebugCollection

Then add code below to your global functions collection.


<% Sub DebugCollection %>
    <!--#include virtual="/include/DebugCollection.inc"-->
<% End Sub %>

I prefer not to write this code to my GLOBAL.INC file because All included files are called before IIS execute the script, on other words, why do we need to load functions that we rare to use? it will consume our CPU processing! But again, the answer is on your own.

Happy Scripting, eh, programming ... :-)

P.S. almost all my ASP file has reference to my GLOBAL.INC file.

Happy Programming!


This article was written by Abd Shomad, currently a student of School of Telecommunication Technology (STTTelkom) Bandung, Indonesia. Abd is involved in many research projects on Internet related science and often leads some real work teams during his studies.


ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article