
CopyTo | 417
SessionState
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Example
The example declares a local variable, sets its value, and adds an item to the
Session collection with the value of the local variable:
Sub Page_Load( )
Dim myBaz As String = "baz"
Session.Add("baz", myBaz)
Dim I as Integer
For I = 0 To Session.Count - 1
Message.Text &= CStr(Session(I)) & "<br/>"
Next
End Sub
Notes
The Add method, which is new in ASP.NET, provides a technique for adding
items to the Session collection, which is consistent with the technique used for
adding items to other .NET collections.
Clear
Session.Clear( )
Clears the contents of the Session collection for the current user.
Parameters
None
Example
The example clears the contents of the Session collection and writes a message to
the Text property of the Message label control that includes the current count of
the collection, which should be 0:
Sub Page_Load( )
Session.Clear( )
Message.Text = "There are " & Session.Count & _
" items in the Session collection."
End Sub
Notes
The Clear method, which is new for ASP.NET, clears only the contents of the
Session collection itself. It does not clear the contents of the StaticObjects
collection.
CopyTo
Session.CopyTo(ByVal array As Array, ByVal index As Integer)
Copies the contents of the Session collection to a one-dimensional array.
Parameters