Export (0) Print
Expand All

Session.Contents Collection

IIS 6.0

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.

Key

The name of the property to retrieve.

You can use an iterating control structure to loop through the keys of the Contents collection, as demonstrated in the following example:


<%@ LANGUAGE="VBSCRIPT" %> 
<% 
  Response.Write "SessionID: " & Session.SessionID & "<P>" 

  ' Remove the session contents in case the request is a refresh. 
  Session.Contents.RemoveAll 

  ' Add a test array to the Session.Contents collection. 
  Dim myArray(2) 
  myArray(0) = "Sunday" 
  myArray(1) = "Monday" 
  myArray(2) = "Tuesday" 
  Session.Contents.Item("MyArray") = myArray 

  ' Add a test object to the Session.Contents collection. 
  Dim myObject 
  Set myObject = Server.CreateObject("adodb.connection") 
  Set Session.Contents.Item("MyObject") = myObject 

  ' Add a test string to the Session.Contents collection. 
  Session.Contents.Item("MyScalar") = "1234567890ABCDEFG" 

  ' Display the Session.Contents collection. 
  Response.Write Session.Contents.Count & " items are in Session.Contents collection:<HR>" 
  Dim sessItem 
  For Each sessItem In Session.Contents 
    If IsArray(Session.Contents.Item(sessItem)) Then 
      Response.write sessItem & " : an array of the following " _ 
& UBound(Session.Contents.Item(sessItem))+1 & " items <BR>" 
      For each objArray in Session.Contents.Item(sessItem) 
        Response.write "- " & objArray & "<BR>" 
      Next 
    ElseIf IsObject(Session.Contents.Item(sessItem)) Then 
      Response.write(sessItem & " : Session object cannot be displayed." & "<BR>") 
    Else 
      Response.write(sessItem & " : " & CStr(Session.Contents.Item(sessItem)) & "<BR>") 
    End If 
  Next  
%> 

Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.

Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

Product: IIS

Show:
© 2014 Microsoft