Session state with load balancing

R

Robert

In Web.config file is a setting for sessionState. If I
want to maintain a users' session state (ie use the
Session object) in a web farm that is being load balanced
by a Cisco CSS 11501 Switch. How do I setup sessionState
so anything saved to the Session object stays with that
session no matter what web server they get bounced around
to?
 
G

Guest

Robert

I think what you really want to do is provide Session state that supports load balancing. This is better than trying to maintain server-adherence since that sort of defeats the purpose of load balancing

There are two ways to do this, one is to use a "StateServer" service. This is very easy to do, just pick a machine to be your state server and point all the machines on your farm to that server in the session cofniguration

The other way is to use SQLServer session state. This stores all of the state information in a SQL server of your choosing. This is my personal preference because our SQL Servers have a fail over strategy that will ensure that the farm is never down, where if yo use the state server method you are relying on a single machine being up and running, and if it goes down your farm dies

There are a couple things you will want to pay careful attention to when setting up farm session state

1. Make sure you have the same MachineKey configured in your machine.config file on all machines on the farm. The reason for this is that the view state (stored on the client) is encrypted using the machine key of the server that served the page. If you bounce between two or machines within a single session you will get an error that you have an invalid view state

2. Double check all of your application config files. By default, Visual Studio.NET will create a web.config for each ASP.NET project you create. The settings in this file default to InProcess session state. This will cause problems because this setting will override the setting in your machine.config and you will be ripping your hair out. The easiest thing to do is to just delete the web.config file entirely if you are not using it, or if you are using it, delete the Session configuration block from it so that your web application uses the default you conifugred in the machine.config

I hope this helps, if you need more help or examples, just let me know

Thanks
-Cla

Clayton Gulick, MCSD
 
Joined
Jan 30, 2009
Messages
1
Reaction score
0
Unable to get load balancing working for us

Hi,

We have setup load balancing and using sql server as session state mode. We have also setup machine config file to use exact machine key settings. The only difference that we may have is that we are using NHibernate in our application. We are experiencing different issues, like forms control disappear, on log out the session does not expire and data not being fetched. This is all random, sometimes it works sometimes not.

I verified that the session id remains the same on postback. I have absolutely no idea what's going on. My best guess is view state is getting corrupt. We have two machines running on the farm. Each machine has a web server and a media server installed on it. Both web and media servers are being load balanced.

Any help is greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top