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.

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

System::Object
  System.Web.SessionState::SessionStateUtility

public ref class SessionStateUtility abstract sealed 

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticSerializationSurrogateSelector

Gets or sets a serialization surrogate selector that is used for session serialization customization.

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticAddHttpSessionStateToContext(HttpContext^, IHttpSessionState^)

Applies the session data to the context for the current request.

System_CAPS_pubmethodSystem_CAPS_staticGetHttpSessionStateFromContext(HttpContext^)

Retrieves session data from the context for the current request.

System_CAPS_pubmethodSystem_CAPS_staticGetSessionStaticObjects(HttpContext^)

Gets a reference to the static objects collection for the specified context.

System_CAPS_pubmethodSystem_CAPS_staticIsSessionStateReadOnly(HttpContext^)

Gets a value which indicates whether the session state is read-only for the specified HttpContext.

System_CAPS_pubmethodSystem_CAPS_staticIsSessionStateRequired(HttpContext^)

Gets a value which indicates whether the session state is required for the specified HttpContext.

System_CAPS_pubmethodSystem_CAPS_staticRaiseSessionEnd(IHttpSessionState^, Object^, EventArgs^)

Executes the Session_OnEnd event defined in the Global.asax file for the ASP.NET application.

System_CAPS_pubmethodSystem_CAPS_staticRemoveHttpSessionStateFromContext(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

GetHttpSessionStateFromContext method

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.

RemoveHttpSessionStateFromContext method

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.

No code example is currently available or this language may not be supported.

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>

.NET Framework
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.

Return to top
Show: