Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 276
Rick Avatar asked Feb 24 '26 08:02

Rick


2 Answers

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

like image 56
Thomas Petersen Avatar answered Feb 27 '26 02:02

Thomas Petersen


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.

like image 37
Henk Holterman Avatar answered Feb 27 '26 02:02

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!