Name

Session

Synopsis

HttpSessionState = Page.Session

Returns an object that represents the current user session. A Session object is maintained for each user that requests a page from an ASP.NET application. You can store session-specific data in the Session object and then access it across multiple pages in an ASP.NET application. For more information on the HttpSessionState class, see Chapter 19.

Parameters

HttpSessionState

An HttpSessionState object that represents the current user session.

Example

The example uses the Session object to display the value of the Mode property, which indicates where session state information is stored:

Sub Page_Load(  )
   Message.Text = "Current Session State Mode: " &_
           Session.Mode.ToString(  )
End Sub

Notes

As with the Request and Response properties, while you can retrieve a local reference to the HttpSessionState instance associated with the request, it is more common to access this instance directly through the Session property, as shown in this example.

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.