IHttpSessionState Interface


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Defines the contract to implement a custom session-state container.

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

type IHttpSessionState = interface end


Gets or sets the code-page identifier for the current session.


Gets a value that indicates whether the application is configured for cookieless sessions.


Gets the number of items in the session-state item collection.


Gets a value indicating whether the session ID is embedded in the URL or stored in an HTTP cookie.


Gets a value indicating whether the session was created with the current request.


Gets a value indicating whether the session is read-only.


Gets a value indicating whether access to the collection of session-state values is synchronized (thread safe).


Gets or sets a session-state item value by numerical index.


Gets or sets a session-state item value by name.


Gets a collection of the keys for all values stored in the session-state item collection.


Gets or sets the locale identifier (LCID) of the current session.


Gets the current session-state mode.


Gets the unique session identifier for the session.


Gets a collection of objects declared by <object Runat="Server" Scope="Session"/> tags within the ASP.NET application file Global.asax.


Gets an object that can be used to synchronize access to the collection of session-state values.


Gets and sets the time-out period (in minutes) allowed between requests before the session-state provider terminates the session.


Ends the current session.

System_CAPS_pubmethodAdd(String, Object)

Adds a new item to the session-state collection.


Clears all values from the session-state item collection.

System_CAPS_pubmethodCopyTo(Array, Int32)

Copies the collection of session-state item values to a one-dimensional array, starting at the specified index in the array.


Returns an enumerator that can be used to read all the session-state item values in the current session.


Deletes an item from the session-state item collection.


Clears all values from the session-state item collection.


Deletes an item at a specified index from the session-state item collection.

A session-state container provides access to the session-state values and related information for the current session. Session information included in a session-state container is exposed to application code through the HttpSessionState class using the Session property. The HttpSessionState class is a wrapper class for a session-state container.

The ASP.NET implementation of a session-state container is the HttpSessionStateContainer class. At the beginning of a request, during the AcquireRequestState event, the SessionStateModule creates and populates an HttpSessionStateContainer object and assigns it to the current HttpContext. At the end of a request, during the ReleaseRequestState event, the SessionStateModule retrieves the HttpSessionStateContainer object from the current HttpContext and performs any required session work, such as writing the session values to the session store, or abandoning the session. If the request is abruptly terminated, such as through a redirect, the SessionStateModule performs the same cleanup by calling the EndRequest method.

To create a custom session-state container, create a class that implements the IHttpSessionState interface. If you are creating your own custom session-state container, you must also replace the SessionStateModule with your own custom module. Your custom module will create an instance of your custom session-state container and add it to the current HttpContext using the AddHttpSessionStateToContext method. An example of a custom session-state module is included in the SessionStateUtility class overview.

The following code example implements the IHttpSessionState interface to create a new session-state container class named MySessionState.

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

.NET Framework
Available since 2.0
Return to top