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

How does ASP.Net work with session data in a load balanced environment? Say a user makes multiple requests while navigating multiple pages? All requests are sent to the same server in the load balancer?

What if they do not all point to the same server? How do I process session data?

+8
session load-balancing
source share
4 answers

You need to make sure your NLB has the ability to enable sticky sessions.

If this is not an option, you need to look at "ASP.Net Session Modes" to configure a session server, or some support repository such as SQL Server.

+4
source share

In most cases, most load balancers try to have permanent connections, but you cannot guarantee this for your purposes. It’s best to use something like an SQL server to maintain state or create a separate class to manage your session data. In any case, you can rebuild the session data if this happens when you expect it to be otherwise. I try to use getters to check for a null value and restore if necessary. In practice, I did not do any indicators to see how often it is being rebuilt, but I would not have suggested it very often. Better to be safe than sorry, as they say.

+1
source share

Load balancers can usually be configured using what the infrastructure guys call sticky session or sticky bit . In this type of environment, once a request has been assigned to a server; he stays with this server throughout the session.

When load balancers are not configured this way, ASP.NET offers several session state providers. One of the most popular is the SQL Server State Provider , which allows you to store session information in a database. For this to work, all objects placed in a Session object must be Serializable so that they can be stored in a table.

As I said, there are several more alternatives; for example, some people prefer a different approach, such as memcached or similar products.

+1
source share

You can use NLB from Windows or other products such as BIG-IP F5, HA Proxy, there are many options.

Use Out-of-Proc (State Server) and make sure that your computer settings are the same on all your servers. Also make sure that you are doing IO on a shared drive such as a NAS.

Here is a link to some tips: Load balancing and ASP.NET

+1
source share

All Articles