SessionStateSection Class

Configures the session state for a Web application.

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

public sealed class SessionStateSection : ConfigurationSection

The SessionStateSection class refers to the element in the Machine.config or Web.config configuration file identified by the sessionState tag.

When a new client begins interacting with a Web application, a session ID is issued and associated with all the subsequent requests from the same client during the time the session is valid. This ID is used to maintain server-side state associated with the client session across requests. The SessionStateSection controls how the ASP.NET application establishes and maintains this association on behalf of each client.

This mechanism is very flexible and gives you the ability to host session-state information out of process and to track state without using cookies, among other things.

This section provides two code examples. The first demonstrates how to specify values declaratively for several attributes of the sessionState section, which can also be accessed as members of the SessionStateSection class. The second demonstrates how to use the T:System.Web.Configuration.SessionStateSection class.

The following configuration file example shows how to specify values declaratively for the sessionState section.

<configuration>
  <system.web>
    <sessionState mode="InProc" 
      stateConnectionString="tcpip=127.0.0.1:42424" 
      stateNetworkTimeout="10"
      sqlConnectionString="data source=127.0.0.1;
        Integrated Security=SSPI"
      sqlCommandTimeout="30" 
      customProvider="" 
      cookieless="UseDeviceProfile" 
      cookieName="ASP.NET_SessionId" 
      timeout="20" 
      allowCustomSqlDatabase="False" 
      regenerateExpiredSessionId="False" 
      partitionResolverType="" 
      useHostingIdentity="True">
      <providers>
        <clear />
      </providers>
    </sessionState>
  </system.web>
</configuration>

The following code example demonstrates how to use the T:System.Web.Configuration.SessionStateSection class.

// Get the Web application configuration object.
System.Configuration.Configuration configuration =
  System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnetTest");

// Get the section related object.
System.Web.Configuration.SessionStateSection sessionStateSection =
  (System.Web.Configuration.SessionStateSection)
  configuration.GetSection("system.web/sessionState");

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft