Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Session Property
Collapse the table of content
Expand the table of content

Page.Session Property

Gets the current Session object provided by ASP.NET.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

[BrowsableAttribute(false)]
public virtual HttpSessionState Session { get; }

Property Value

Type: System.Web.SessionState.HttpSessionState
The current session-state data.

ExceptionCondition
HttpException

Occurs when the session information is set to null.

This property provides information about the current request's session. A Session object is maintained for each user that requests a page or document from an ASP.NET application. Variables stored in the Session object are not discarded when the user moves from page to page in the application; instead, these variables persist as long as the user is accessing pages in your application. For more information about session state, see ASP.NET Session State Overview.

TopicLocation
How to: Read Values from Session StateBuilding ASP .NET Web Applications
How to: Sample Session-State Store ProviderBuilding ASP .NET Web Applications
How to: Save Values in Session StateBuilding ASP .NET Web Applications
How to: Read Values from Session StateBuilding ASP .NET Web Applications
How to: Sample Session-State Store ProviderBuilding ASP .NET Web Applications
How to: Save Values in Session StateBuilding ASP .NET Web Applications

The following code example creates a GetStyle function that retrieves a key stored in the session state of the Web Forms page and converts its value to a string.

// Create a private function that obtains
// information stored in Session state
// in the application's Global.asax file.
// When this method is called and a key name
// that is stored in Session state is passed
// as the paramter, the key is obtained and
// converted to a string.
String GetStyle(String key) {
  return Session[key].ToString();       
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Show:
© 2015 Microsoft