The Contents collection contains all session variables. You can loop through the Contents collection, to see what's stored in it:

<%
Session("username")="Donald Duck"
Session("age")=50

dim i
For Each i in Session.Contents
  Response.Write(i & "<br>")
Next
%>

Result:

username
age

If you do not know the number of items in the Contents collection, you can use the Count property:

<%
dim i
dim j
j=Session.Contents.Count
Response.Write("Session variables: " & j)
For i=1 to j
  Response.Write(Session.Contents(i) & "<br>")
Next
%>

Result:

Session variables: 2
Donald Duck
50



Practice Excercise Practice now