
418
|
Chapter 19: The HttpSessionState Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
index
An integer argument specifying the point in the array at which to begin
copying.
Example
The example checks to ensure that at least one item is in the Session collection,
and if there is, it creates a local object array, copies the contents of the Session
collection to it, and displays the value of the first item:
Sub Page_Load( )
If Session.Count > 0 Then
Dim myArray As Array = Array.CreateInstance(GetType(Object), _
Session.Count)
Session.CopyTo(myArray, 0)
Message.Text = "The first item in the array is: " & _
CStr(myArray(0))
End If
End Sub
Notes
The CopyTo method is useful if you have a large number of items stored in the
Session collection. In such cases, accessing values from a local array variable may
be faster and more efficient than accessing the values from the Session collection,
particularly when session state is configured to run out of process. The improved
efficiency and performance comes at the cost of ease of use, since arrays do not
provide the same feature richness as the Session collection.
Remove
Session.Remove(ByVal name As String)
Removes an item from the Session collection by name.
Parameter
name
A string argument containing the name (key) of the item to remove.
Example
The example determines whether the item with the