alt
Advertisement
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow ASP.NET arrow Managing State with ASP.NET and C#
Site Search


Managing State with ASP.NET and C#
Article Index
Managing State with ASP.NET and C#
Page 2
Page 3

Configuring Session State

You can configure the session state in your web.config file. This means that the settings that you will do in the web.config file will be affected to the whole application. Let's see how we can do this:

Configuring In-Process Mode

In-process is the default session state mode. To use in-process mode, set the mode attribute of the element to Inproc.

The following shows a sample configuration setting for in-process mode.



cookieless="false"
timeout="20"/>




(msdn)

Configuring State Server Mode

To use State Server, you must first make sure ASP.NET state service is running on the remote server used for the session store. This service is installed with ASP.NET and Visual Studio .NET at the following location:

systemroot\Microsoft.NET\Framework\versionNumber\aspnet_state.exe

Next, set the mode attribute of the element to StateServer in the Web.config file of the application. Finally, set the connectionString attribute to tcpip=serverName:portNumber.

The following shows a sample configuration setting for State Server mode.



stateConnectionString="tcpip=dataserver:42424"
cookieless="false"
timeout="20"/>




(msdn)

Configuring SQL Server Mode

To use SQL Server, first run either InstallSqlState.sql or InstallPersistSqlState.sql on the computer with SQL Server that will store the session state. Both scripts create a database called ASPState that includes several stored procedures. The difference between the scripts is where the ASPStateTempApplications and ASPStateTempSessions tables are placed. The InstallSqlState.sql script adds these tables to the TempDB database, which loses session data if the computer is restarted. The InstallPersistSqlState.sql script, on the other hand, adds these tables to the ASPState database, which allows session data to be retained when the computer is restarted.

Both of these script files are installed by default at the following location:

systemroot\Microsoft.NET\Framework\versionNumber

Next, set the mode attribute of the element to SQLServer in the Web.config file of the application. Finally, set the sqlConnectionString attribute to Integrated Security=SSPI;data source=serverName;.

The following shows a sample configuration setting for SQL Server mode.



sqlConnectionString=" Integrated Security=SSPI;data source=dataserver;"
cookieless="false"
timeout="20"/>


In SQL Server mode, session state can also be configured to work in a failover cluster. A failover cluster is two or more identical, redundant Web servers that store their session data on a separate computer in a SQL Server database. If a Web server fails, another server in the cluster can take over and serve requests without session data loss. To configure a failover cluster, set the element in the Web.config file of the Web servers to the same value. Then set the SQL connection string of the Web servers to point to the SQL Server database on the computer that stores the session data.

(msdn)



 
< Prev   Next >
Sponsored Links
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape