5
votes

I manage shared session state across 2 production web servers using SQL Server database.
Recently I realized (And I am almost sure that this wasn't the case before) that the session is not really shared when jumping from server to server.

Both servers run the same website on the same domain and are balanced using a hardware load balancer. Both run under IIS7. And in both servers the ASP.NET State Service is running.

When inspecting the HTTP headers and cross referencing with SQL profiler captures I found what I think might be the problem.

The SessionId value in my cookies is a 24 character string, e.g: y4hfairc2xbwlupkdsqpv0nz

The SessionID as recieved by the ASPState database and as stored there is longer and has server specific 8 character postfix. e.g. 2476b033 or 2b7731d2 which is consistent across all sessions stored in the database.
The SessionIDs therefore look like: y4hfairc2xbwlupkdsqpv0nz2476b033 or y4hfairc2xbwlupkdsqpv0nz2b7731d2

Obviously because of that the session is not shared and each server maintains its own session state.

Anyone using a similar configuration that might have encountered this before?

Thanks

update

Turns out here: SessionId saved in SQL Server is different from the one generated from the asp.net runtime that the extra characters are the IIS AppID. Now I have to find out how to change it so both servers will match. So far no luck.
Anyone?

1
Have you checked the machine key is the same on both web servers? There's info at wiki.asp.net/page.aspx/1248/aspnet-and-load-balancingAndrew Morton
yes. Just rechecked to be sure. the web.config files are identicalVariant
One difference that does exist is that for each of the servers there is also a binding to a different subdomain that enables us to access this server directly. however I don't think that is the case as I access the site usign the balanced domain name and this is also the domain for the session cookie.Variant

1 Answers

3
votes

Answering my own question for completeness.

Thanks to this: https://serverfault.com/questions/288981/load-balanced-iis-7-5-web-server-asp-net-session-state-problem

I found out how to match the AppIDs.

Everything seems to work great now.