.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Web.Config : <sessionState> Element

Posted By:Baimey Rajesh       Posted Date: August 23, 2012    Points: 200    Category:    URL: http://www.dotnetspark.com  

Managing session state using a sessionState tag in web.config
 

The session time-out refers to the number of minutes before the user session is aborted. If a large file is being uploaded it is desirable to maintain the session state. The session time-out should always be longer than the amount of time you expect uploads to take.

NB: this value is only relevant if you have session state enabled.

<configuration>
   <system.web>
      <sessionState/>

ASP.NET session state supports several different storage options for session data.

 SessionStateMode enumeration can have the following values

·         InProc mode, which stores session state in memory on the Web server. This is the default.

·         StateServer mode, which stores session state in a separate process called the ASP.NET state service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

·         SQLServer mode stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

·         Custom mode, which enables you to specify a custom storage provider.

·         Off mode, which disables session state.

InProc Mode

In-process mode stores session state values and variables in memory on the local Web server. It is the only mode that supports the Session_OnEnd event.

StateServer Mode

<configuration>
  <system.web>
    <sessionState mode="StateServer"
      stateConnectionString="tcpip=SampleStateServer:42424"
      cookieless="false"
      timeout="20"/>
  </system.web>
</configuration>

To configure an ASP.NET application to use StateServer mode, in the application's Web.config file do the following:

·         Set the mode attribute of the sessionState element to StateServer.

·         Set the stateConnectionString attribute to tcpip=serverName:42424.

·          It is recommended that you protect your stateConnectionString value by encrypting

·         In a Web farm, you must have the same encryption keys specified in the machineKey element of your Web configuration for all applications that are part of the Web farm.

NB: Objects stored in session state must be serializable if the mode is set to StateServer

SQL Server Mode

 

<configuration>
  <system.web>
    <sessionState mode="SQLServer"
      sqlConnectionString="Integrated Security=SSPI;data 
        source=SampleSqlServer;" />
  </system.web>
</configuration>

SQLServer mode stores session state in a SQL Server database.

NB: Objects stored in session state must be serializable if the mode is SQL Server.

To configure an ASP.NET application to use SQLServer mode, do the following in the application's Web.config file:

·         Set the mode attribute of the sessionState element to SQLServer.

·         Set the sqlConnectionString attribute to a connection string for your SQL Server database.

Custom Mode

Custom mode specifies that you want to store session state data using a custom session state store provider.

 

<configuration>
  <connectionStrings>
    <add name="OdbcSessionServices" 
      connectionString="DSN=SessionState;" />
  </connectionStrings>
 
  <system.web>
    <sessionState 
      mode="Custom"
      customProvider="OdbcSessionProvider">
      <providers>
        <add name="OdbcSessionProvider"
          type="Samples.AspNet.Session.OdbcSessionStateStore"
          connectionStringName="OdbcSessionServices" 
          writeExceptionsToEventLog="false" />
      </providers>
    </sessionState>
  </system.web>
</configuration>

When you configure your ASP.NET application with a Mode of Custom, you must specify the type of the session state store provider using the providers sub-element of the sessionState configuration element. 

 

Off  Mode

In off mode the session state is disabled.

 

Hope you have got an Idea of session state setting using web.config.

Happy Coding J

Baimey




     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend