Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net - Handling session data in a load balanced environment?

How does ASP.Net deal with session data in a load balanced environment? Let's say a user makes multiple requests while navigating through a couple of pages? Do all requests go to the same server in the load balancer?

What can I do if they don't all point to the same server? how do I deal with my session data?

like image 350
aryaxt Avatar asked Sep 28 '11 02:09

aryaxt


2 Answers

You need to ensure that your NLB has the ability to enable "Sticky" sessions.

If this isn't an option, then you need to look at using the ASP.Net Session Modes to configure either a Session Server, or some backing store like SQL Server.

like image 62
Josh Avatar answered Sep 30 '22 03:09

Josh


In general most load balancers try to have persistent connections but for your purposes you can't guarantee it. You're best off either using something like an SQL backend to maintain state or create a separate class to manage your session data. In either case you can then rebuild the session data if it happens to be null when you expect it to be otherwise. I tend to use the getters to check for null and rebuild when necessary. In practice I haven't done any metrics to see how often it is rebuilt but I'd guess not very often. Better to be safe than sorry, as they say.

like image 37
McArthey Avatar answered Sep 30 '22 03:09

McArthey