Export (0) Print
Expand All

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.

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

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

public ref class SessionStateUtility abstract sealed

The SessionStateUtility type exposes the following members.

  NameDescription
Public propertyStatic memberSerializationSurrogateSelectorGets or sets a serialization surrogate selector that is used for session serialization customization.
Top

  NameDescription
Public methodStatic memberAddHttpSessionStateToContextApplies the session data to the context for the current request.
Public methodStatic memberGetHttpSessionStateFromContextRetrieves session data from the context for the current request.
Public methodStatic memberGetSessionStaticObjectsGets a reference to the static objects collection for the specified context.
Public methodStatic memberRaiseSessionEndExecutes the Session_OnEnd event defined in the Global.asax file for the ASP.NET application.
Public methodStatic memberRemoveHttpSessionStateFromContextRemoves session data from the specified context.
Top

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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft