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

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.

Product Manager, Testing (PA)
Next Step Systems
US-PA-Wayne

Justtechjobs.com Post A Job | Post A Resume

Published: Saturday, October 09, 1999

Listing Session and Application Variables


Have you ever wondered how to list all of your Session and Application variables? Both the Session and Application objects provide the Contents collection, which contains all of the session and application variables that are not objects (i.e., arrays, strings, integers, etc.).

- continued -

You can loop through this collection using the For Each ... Next. Since arrays are included in the Contents collection, we need to determine if the current variable is an array, using the IsArray function. If the variable is an array, we need to loop through the array one element at a time, displaying each element. If the variable is not an array, we need to simply display the variable.

Well, enough chatter, here is the code!

<%@ Language=VBScript %>
<% Option Explicit %>
<% 'How many session variables are there? Response.Write "There are " & Session.Contents.Count & _ " Session variables<P>" Dim strName, iLoop 'Use a For Each ... Next to loop through the entire collection For Each strName in Session.Contents 'Is this session variable an array? If IsArray(Session(strName)) then 'If it is an array, loop through each element one at a time For iLoop = LBound(Session(strName)) to UBound(Session(strName)) Response.Write strName & "(" & iLoop & ") - " & _ Session(strName)(iLoop) & "<BR>" Next Else 'We aren't dealing with an array, so just display the variable Response.Write strName & " - " & Session.Contents(strName) & "<BR>" End If Next %>

You can list the Application variables by simply changing each instance of the word Session in the code above with the word Application!

Happy Programming!


  • View the code for this article in text format


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