Session Contents Collection

The Session.Contents collection contains all of the items that have been established for a session without using the <OBJECT> tag. The collection can be used to determine the value of a specific session item, or to iterate through the collection and retrieve a list of all items in the session.

Syntax

Session.Contents( Key )

 

Parameters
Key
The name of the property to retrieve.
Remarks

You can use an iterating control structure to loop through the keys of the Contents collection. This is demonstrated in the following example.

<%@ LANGUAGE="VBSCRIPT" %>
<%
  Dim sessitem
  Dim anArray(2)
  response.write "SessionID: " & Session.SessionID & "<P>"

  anArray(0)="one"
  anArray(1)="second"
  anArray(2)="third"
  Session("anArray")=anArray
  Session("scalar")="1234567890ABCDEFG"

  set objConn=server.createobject("adodb.connection")
  set Session("object")=objConn

  response.write "List of " & Session.Contents.Count & " items in Session
  contents collection:<HR>"
  For Each sessitem in Session.Contents
    If IsObject(Session.Contents(sessitem)) Then
      Response.write(sessitem & " : Session object cannot be displayed." & "<BR>")
    Else
      If IsArray(Session.Contents(sessitem)) Then
         Response.write "Array named " & Session.Content(sessitem) & "<ol>"
         For each objArray in Session.Contents(sessitem)
             Response.write "<li>" & _
             Session.Contents(sessitem)(objArray)& "<BR>"
         Next
             Response.write "</ol>"
      Else
             Response.write(sessitem & " : " & Session.Contents(sessitem) & "<BR>")
       End If
    End If
  Next 
%>