开发者

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 t开发者_开发知识库he 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.


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

When Load Balancers are not configured in such a way, ASP.NET offers several session state providers. One very popular is the SQL Server State Provider, which allows session information to be stored in a database. In order for this to work, all objects placed in the 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 to use a different approach such as memcached or similar products.


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

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

Here is a link with some more tips: Load Balancing and ASP.NET

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜