Exforsys.com
 

Sponsored Links

 

ASP.NET Tutorials

 
Home Tutorials ASP.NET
 

Managing State with ASP.NET and C#

 

Managing State with ASP.NET and C# - Page 2

Page 2 of 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)




Next Page: Managing State with ASP.NET and C# - Page 3


Read Next: Caching in ASP.NET



 

 

Comments


vishal soni said:

  This site is fantastic for beginners and is very helpful
January 9, 2009, 6:24 am

Salim Ahamed said:

  How I can use session for Login page in asp.net and how I can sign out through session. Please help me.
April 24, 2009, 8:43 am

satyam said:

  How I can use Session for LogIn page in asp.net.
October 28, 2009, 3:48 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape