When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

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.


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



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES