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)
| Name | Description | |
|---|---|---|
![]() ![]() | SerializationSurrogateSelector | Gets or sets a serialization surrogate selector that is used for session serialization customization. |
| Name | Description | |
|---|---|---|
![]() ![]() | AddHttpSessionStateToContext(HttpContext, IHttpSessionState) | Applies the session data to the context for the current request. |
![]() ![]() | GetHttpSessionStateFromContext(HttpContext) | Retrieves session data from the context for the current request. |
![]() ![]() | GetSessionStaticObjects(HttpContext) | Gets a reference to the static objects collection for the specified context. |
![]() ![]() | IsSessionStateReadOnly(HttpContext) | Gets a value which indicates whether the session state is read-only for the specified HttpContext. |
![]() ![]() | IsSessionStateRequired(HttpContext) | Gets a value which indicates whether the session state is required for the specified HttpContext. |
![]() ![]() | RaiseSessionEnd(IHttpSessionState, Object, EventArgs) | Executes the Session_OnEnd event defined in the Global.asax file for the ASP.NET application. |
![]() ![]() | RemoveHttpSessionStateFromContext(HttpContext) | 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>
Available since 2.0
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
.jpeg?cs-save-lang=1&cs-lang=fsharp)
.jpeg?cs-save-lang=1&cs-lang=fsharp)
.jpeg?cs-save-lang=1&cs-lang=fsharp)