Hosting a .NET Application in a Web Farm
page 5 of 7
by Tejaswini Das
Feedback
Average Rating: 
Views (Total / Last 10 Days): 37726/ 54

2. Session Maintenance

The default ASP.NET in-process session state handling, results in server affinity and cannot be used in a Web farm scenario. For Web farm deployments, the session state must be stored out of process in either the ASP.NET State service or a SQL Server database.

Out of Process Mode

In the Out of Process mode, the session information is stored in a separate “state server” process. The worker process ("aspnet_wp.exe") will communicate with the state server ("aspnet_state.exe") to retrieve session information. However, the use of state server mode can affect the performance of the application by 10-15%. The main reason for this performance hamper is due to the fact that session information resides in a separate process (i.e. in a memory area outside the direct control of the asp_net worker process). So with every request, the worker process has to get the session values from a separate process.

To keep session information outside the worker process, the objects inside the session must be serializable. So with end of every request, the objects inside the session are serialized and with the beginning of each request, the objects are de-serialized.

To continue to use the state server model, the sessionstate parameter in the web.config file needs to be updated.

Listing 5:

<configuration>
  <sessionstate 
    mode="stateserver"
    cookieless="false" 
    timeout="20" 
    sqlconnectionstring="data source=127.0.0.1;user id=userid;password=password"
    server="127.0.0.1"
    port="42424"/>
</configuration>

The default data source is set to the local machine so if the state server is on a different machine as that of the application then the correct machine name should be given on the web.config file.

SQL Server Mode

In the SQL Server mode the information is stored in the SQL Server rather than memory. But to use the SQL Server session state, we need to create the necessary tables and the stored procedures that ASP.NET will look for on the identified SQL Server. The SQL Server mode affects the performance to a greater degree, but makes the session information more secure as we can have two or more identical computers running SQL server for a single database. So if one computer fails another computer can take over and serve requests without session data loss.

For applications in ASP.NET 1.1 and SQL 2000

To configure to use the SQL Server mode, the sessionstate parameter in the web.config needs to be updated.

Listing 6

<configuration>
 <sessionstate 
  mode="sqlserver"
  cookieless="false" 
  timeout="20" 
  sqlconnectionstring="data source=MySqlServer;user id=ASPState;password=1Gr8State"
  server="127.0.0.1" 
  port="42424" />
</configuration>

Configure the SQL Server to store Session objects by running a script to create the ASPState database. Version 1.0 of the .NET Framework provides a state database configuration script in %SYSTEMROOT%\Microsoft.NET\Framework\v1.0.3705\InstallSqlState.sql. If you open the file, you will see a statement to create a database called ASPState.

For applications in ASP.NET 2.0 and SQL 2005

To install the session state database on SQL Server, run Aspnet_regsql.exe tool and supply the following information with the command.

• The name of the SQL Server instance, using the -S option

• The logon credentials for an account that has permission to create a database on a computer running SQL Server: Use the -E option to use the currently logged-on user, or use the -U option to specify a user ID along with the -P option to specify a password.

• The -ssadd command-line option to add the session state database

Listing 7

aspnet_regsql.exe -S <SQL Server name> -U <User Name> -P <Password> -ssadd -sstype p

You can run Aspnet_regsql.exe without any command-line arguments to run a wizard that will walk you through specifying connection information for your SQL Server database and installing or removing the database elements for supported features. You can also run Aspnet_regsql.exe as a command-line tool to specify database elements for individual features to add or remove.

To run the wizard, run Aspnet_regsql.exe without any command-line arguments, as shown in the following example.

Listing 8

C:\%windir%\Microsoft.NET\Framework\<versionNumber>\aspnet_regsql.exe

View Entire Article

User Comments

Title: Nice Article   
Name: Fidha
Date: 2010-09-28 4:22:28 AM
Comment:
Hi Dass - This is a nice article. Thank You.
Title: Hosting a .NET Application in a Web Farm   
Name: Gandhi Basnet
Date: 2010-08-19 9:58:13 AM
Comment:
The article is superb. Now I understand web farm clearly and which session state is applicable for it. I was asked this question in a interview.

Thanks a lot.
Title: Conceptual and contextual mistakes in your article   
Name: Eriawan Kusumawardhono
Date: 2010-04-26 3:05:58 AM
Comment:
There are quite numerous mistakes in your article.
They are:
- The article should be titled 'Hosting ASP.NET application..' instead of .NET application
- The article has no mention of the fact that load balancing configuration of IIS to be used in web farms has to be configured separately, and it can only be configured in Windows Server OS, not in client OS such as Windows XP or Vista.
- Using SQL Server to store ASP.NET session data means that you have to install this database server separated with the web servers, otherwise the intention of added performance will be nothing. Also the server farm of the web server has to point to the same db server.

It's true that you can't use in proc configuration easily in a web farm configuration, but it can be done.
Title: Nice article   
Name: Sanjivani
Date: 2010-02-17 3:21:34 AM
Comment:
Very useful and informative..explained the concept in short and sweet way.

Thanks!
Sanjivani
Title: mistake in your article   
Name: vishnu vardhan, Hyderabad.
Date: 2010-01-04 7:59:40 AM
Comment:
Please currect the word "Web Form" instead of "Web Farm".
I think it is not a web farm, it is Web form.

with regards
vishnu.
Title: good work   
Name: Pawan Pawar
Date: 2009-11-30 2:22:17 AM
Comment:
gr8 work...

i appericiate with article
Title: superb   
Name: praveen
Date: 2009-07-07 5:42:47 AM
Comment:
Thanks Das for posting very informative and most useful article.
Title: Really Good   
Name: Milind Mahajan
Date: 2008-07-16 2:23:42 AM
Comment:
really very good article. every dot net developer should read it... keep going
Title: Good one   
Name: Vishal Khanna
Date: 2008-05-14 2:14:01 PM
Comment:
Thanks Mr. Das. Nice article. Good explanation of using Aspnet_regsql.exe.
Title: Another way to create key   
Name: ashu fouzdar
Date: 2008-04-28 8:27:24 AM
Comment:
One can also use the following url for generating keys :

http://www.eggheadcafe.com/articles/GenerateMachineKey/GenerateMachineKey.aspx

It is very nice web based key generater
Title: Good Job   
Name: Abhishek
Date: 2007-08-01 1:30:46 AM
Comment:
Nice work. Keep it up :-)

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 10:02:16 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search