'in-proc' Session State mode on a multiple server setup?

6.5k views Asked by At

My Team is using 'in-proc' Session State mode on a multiple server setup. This does not seem right to me obviously because the session state is going to be unique on each server and will not be shared.

We have approached this problem by giving the same Machine Key on both servers (in the application's config file.) But I have a feeling this would not actually help...

Any light on this is appreciated.

Thanks!

2

There are 2 answers

3
R.C On BEST ANSWER

When using InProc session state, the session will be stored locally on the server which served the request and therefore using the same Machine Key on both servers won't serve the purpose.

This option is not fit for use in a web farm environment. One farm machine stores the session state but not the other. Subsequent web requests from the same user may not read the correct session state.

Consider a very common scenario:

Imagine that the web request is routed to farm machine A and the code invoked by the request relies on some parameters stored in the session. If the same user is then routed to machine B in the next web request which also relies on the session state then the results will be unpredictable.

There is something called StickySessions which can tackle above scenario. But is it really good ?

This feature means that if a client returns for a second request then the load balancer will redirect that traffic to the same web server. It is also called client affinity. This can be important for web servers that store session state locally so that when the same visitor comes back then we don’t want the state relevant to that user to be unavailable because the request was routed to a different web server.

This definitely beats the very purpose of load balancing in a web farm.We should avoid this solution so that the load balancer can pick the “right” machine in a farm based on the current load.

Read here for a complete understanding: http://dotnetcodr.com/2013/07/01/web-farms-in-net-and-iis-part-5-session-state-management/

0
Khaled Musaied On

You can use AppFabric Session state to mange distributed sessions

http://msdn.microsoft.com/en-us/library/hh361709(v=azure.10).aspx