Name

Add

Synopsis

Session.Add(ByVal name As String, ByVal value As Object)

Adds an item to the Session collection.

Parameters

name

A String argument containing the name that will be used to refer to the new item.

value

An Object argument containing the value of the new item.

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.

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.