views:

540

answers:

3

Does the OnSessionStart / Session_Start event still only fire once (total) in a server farm environment, or since requests are handled by multiple servers, could it fire up to once per server?

ASP.NET / IIS6 or 7

It should not be assumed that the server is using Sticky Sessions.

+1  A: 

my understanding is that once a request reach a server in the farm ,all of the upcoming requests of the same client should be redirected to the same server in the farm.

Oscar Cabrero
That is only true if you have sticky sessions enabled.
Rick
+1  A: 

In a farm, you would be using either Sql Server or a State Server for managing session state across all the servers in the farm. It is having this single server looking after your state than ensures that OnSessionStart should only be called once per session and there is no need to have to always have all the requests go back to the same server.

The main downside of using a single server for maintaining session state is that you no longer have an OnSessionEnd event.

Pervez Choudhury
+3  A: 

With a default installation of IIS the answer is "no" -- the Session_Start will in general fire multiple times. A client will create a new Session on each different server it hits. The same thing goes if you are using the Web Garden option in IIS.

If you don't depend on Session and you have a server farm you are usually best off disabling Session state completely. Here is how you do it: http://support.microsoft.com/kb/306996

If you do depend on Session your best option is probably the ASP.NET State Server Service. All the servers in your farm will use a single server for Session state, and that will ensure that Session_Start only fires once. For lots of background and detail on setup read this (Look for "State Server Mode" to get specific instructions): http://aspdotnetdevs.blogspot.com/2008/12/aspnet-session-state-and-modes.html

Thomas Petersen