Rick
Rick

Reputation: 1913

How does Session_Start() work in server farm?

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.

Upvotes: 3

Views: 2149

Answers (4)

Henk Holterman
Henk Holterman

Reputation: 273439

In addition to Thomas: It depends on your Session State settings.

in web.config, <sessionState mode="" >

If you use mode="InProc" you'll get multiple Session and SessionStart events, 1 per visited server.

In the other modes (StateServer or SqlServer) you'll get 1 session and 1 SessionStart. You will not get a SessionEnd event at all.

Upvotes: 4

Thomas Petersen
Thomas Petersen

Reputation: 1012

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

Upvotes: 5

Pervez Choudhury
Pervez Choudhury

Reputation: 2912

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.

Upvotes: 1

Oscar Cabrero
Oscar Cabrero

Reputation: 4169

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.

Upvotes: 0

Related Questions