SessionStateUtility Class
Provides helper methods used by session-state modules and session-state store providers to manage session information for an ASP.NET application. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
The SessionStateUtility type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | AddHttpSessionStateToContext | Applies the session data to the context for the current request. |
![]() ![]() | GetHttpSessionStateFromContext | Retrieves session data from the context for the current request. |
![]() ![]() | GetSessionStaticObjects | Gets a reference to the static objects collection for the specified context. |
![]() ![]() | RaiseSessionEnd | Executes the Session_OnEnd event defined in the Global.asax file for the ASP.NET application. |
![]() ![]() | RemoveHttpSessionStateFromContext | Removes session data from the specified context. |
The SessionStateUtility class provides static helper methods that are used by a session-state module or a session-state store provider. Application developers will not need to call these methods from their code.
The following table describes the ways the session-state module and session-state store provider use the methods.
Method | Use |
|---|---|
Can be used by custom session-state modules to either retrieve session information for an existing session or create session information for a new session. | |
AddHttpSessionStateToContext method | Called by the session-state module to add the session data to the current HttpContext and make it available to application code through the Session property. |
Called by the session-state module during the ReleaseRequestState or EndRequest events at the end of a request, to clear session data from the current HttpContext. | |
GetSessionStaticObjects method | Called by the session-state module to get a reference to the StaticObjects collection based on objects defined in the Global.asax file. The HttpStaticObjectsCollection collection returned is included with the session data added to the current HttpContext. |
Session data is passed to and retrieved from the current HttpContext as an HttpSessionStateContainer object or any valid implementation of the IHttpSessionState interface.
For information about implementing a session-state store provider, see Implementing a Session-State Store Provider.
The following code example shows a custom session-state module implementation that stores session information in memory using a Hashtable. The module uses the SessionStateUtility class to reference the current HttpContext and SessionIDManager, retrieve the current HttpStaticObjectsCollection, and raise the Session_OnEnd event defined in the Global.asax file for the ASP.NET application. This application does not prevent simultaneous Web requests from using the same session identifier.
To use this custom session-state module in an ASP.NET application, you can replace the existing SessionStateModule reference in the Web.config file, as shown in the following example.
<configuration>
<system.web>
<httpModules>
<remove name="Session" />
<add name="Session"
type="Samples.AspNet.SessionState.MySessionStateModule" />
</httpModules>
</system.web>
</configuration>
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.

