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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With