Load Balancing ASP.NET Sites On Windows Server 2008
November 20th, 2009 | Published in ASP.NET
I have been through this iteration twice now, so I wanted to share what I have found works for me in simple terms to get an ASP.NET site up and running on a set of load balance web servers.
I am not going to discuss the infrastructure site of this setup. That would include setting up your servers with a heartbeat and configuring your ASP.NET sites. The reason for this is that NLB strategies really vary from place to place depending on what hardware and network technology you are using. Setting up IIS sites is frankly very straight-foward, and there is nothing you will do out of the ordinary here.
Lets focus on what we need to do to the application first to get it ready.
If your application uses any sort of Session State objects at all, it is wise to put your session information in SQL Server. The reason behind this is that it really provides the best and most reliable source for keeping session information integrity between your two servers. Besides that, since you are load balancing your application, you need a source for the session state that is available to ALL servers in the farm.
Start out by creating your ASPState database on your database server. There is already a great article you can follow on how to do this here.
Its a rather long article, so let me outline the important stuff…
- Run the Aspnet_regsql.exe tool which is located in the systemroot\Microsoft.NET\Framework\versionNumber directory
- Go through the wizard to create the session database
Now that the ASPState database is created, we setup our ASP.NET application to use it. In your web.config file, you will provide an entry that looks somewhat like the following…
<sessionState
mode=”SQLServer”
sqlConnectionString=”data source=yourDatabase;user id=dbuser;password=pwd”
cookieless=”false”
regenerateExpiredSessionId=”true”
timeout=”30″
/>
The documentation for what all these options do is located here..
http://msdn.microsoft.com/en-us/library/h6bb9cz9(VS.71).aspx
The sessionState block needs to go inside of the system.web section.
Now the next thing we need to do is to handle our View State between all the servers in our farm. The ViewState is tied to the machine on which it is generated. This information can be shared across servers, but it needs to be encrypted and decrypted. Fortunately, this is very easy.
Go to the following site, make no changes to the default settings and let it generate the web config setting that you need for you.
http://aspnetresources.com/tools/keycreator.aspx
Now put this tag in the web config immediately following your sessionState information.
You are now ready to publish your application to each of the load balanced servers.