Export (0) Print
Expand All

HttpContext.Session Property

Gets the HttpSessionState object for the current HTTP request.

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

member Session : HttpSessionState

Property Value

Type: System.Web.SessionState.HttpSessionState
The HttpSessionState object for the current HTTP request.

The Session property provides programmatic access to the properties and methods of the HttpSessionState class. Because ASP.NET pages contain a default reference to the System.Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an .aspx page without using the fully qualified class reference to HttpContext. For example, you can use Session("SessionVariable1") to get or set the value of the session state variable SessionVariable1. However, if you want to use the members of HttpResponse from an ASP.NET code-behind module, you must include a reference to the System.Web namespace in the module and a fully qualified reference to both the currently active request/response context and the class in System.Web that you want to use. For example, in a code-behind page you must specify the fully qualified name HttpContext.Current.Session("SessionVariable1").

You cannot set or get a session-state value if session state is not enabled. To configure session-state settings for an application, set the mode attribute of the sessionState element in the Web.config file. When session state is enabled and you request a value from a session-state variable that does not exist, a null reference (Nothing in Visual Basic) is returned.

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: Display Safe Error MessagesBuilding 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: Display Safe Error MessagesBuilding ASP .NET Web Applications
How to: Save Values in Session StateBuilding ASP .NET Web Applications

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2015 Microsoft