Session.Contents Collection
Session.Contents集合包含了所有的为一个会话建立而不使用<OBJECT>标签的项。该集合可以被用来确定在某个会话中,指定的会话项的值,或者遍历集合,检索所有项的列表。
句法
参数
- Key
- 要检索的属性的名称。
备注
你可以使用一个遍历控制结构来循环遍Contents集合的键,如下面的示例所演示的。
VBScript<%@ LANGUAGE="VBSCRIPT" %> <% Response.Write "SessionID: " & Session.SessionID & "<P>" ' 一旦刷新请求,就删除Session.Contents。 Session.Contents.RemoveAll ' 对Session.Contents集合添加一个测试数组。 Dim myArray(2) myArray(0) = "Sunday" myArray(1) = "Monday" myArray(2) = "Tuesday" Session.Contents.Item("MyArray") = myArray ' 向Session.Contents集合添加一个测试对象。 Dim myObject Set myObject = Server.CreateObject("adodb.connection") Set Session.Contents.Item("MyObject") = myObject ' 把一个测试字符串添加到Session.Contents集合。 Session.Contents.Item("MyScalar") = "1234567890ABCDEFG" ' 显示Session.Contents集合 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