we have a problem with an ASP.NET website where the users' sessions are behaving oddly - session data appearing, disappearing and re-appearing.
I think I know what the problem is:
- Our setup is 2 x Load balanced WebServers + single session state database.
- ASP.NET SQL session state storage appears to depend on the IIS Website Instance ID (Metabase ID) to uniquely identify the incoming session cookie ID and retrieve/store values.
- The IIS Website Instance ID of the website is different on each of the live servers (ID /W3SVC/1/Root on WebServer A, ID /W3SVC/2/Root on Webserver B).
- Load balancing is not using client affinity so each user HTTP request could go to either server.
Therefore, as a user logs onto the site and moves around, each HTTP call can go to either web server, and hence use a Session State record with different IDs depending on the server. In effect the user would simultaneously have 2 separate session instances. I believe I have verified this as in the database ASPStateTempSessions table, each session cookie ID seems to correspond to 2 almost-identically named records (their IDs only differ by the last few characters, which I believe are a modifier based on the AppID from the AspStateTempApplications table) created within seconds of each other.
Therefore Session State will appear to misbehave as changes made to one session record will only persist against that web server. If the User moves to the other load-balanced server, session values will seem to disappear or revert.
I believe the solution is to synchronise the IIS Instance IDs of the sites (e.g. make them both /W3SVC/1/Root), but I tried to edit that value in IIS under Advanced Settings, and although it saved OK, it just made the site return 404s on that server until I changed it back.
I found a VBS script for this problem but it seems to be for IIS 6 only so I'm worried about trying it. Has anybody else encountered this situation on IIS 7.5, and how did you fix it?
EDIT / SOLUTION
My mistake was that I forgot to restart IIS after I changed the Site Instance ID in IIS. After this, the ID was updated and ASP.NET sessions were synced on the two web servers.
- Remote Desktop onto server LIVE1, open IIS Mgr, click on the problem Site and choose Advanced Settings in the sidebar.
- Change the ID to something unique e.g. 10. Click OK.
- Restart the web service (
Do the same for LIVE2 (ensure the Site ID is the same as on LIVE1)
Note that the site ID does affect the location of site files e.g log file folder would become
C:\inetpub\logs\LogFiles\W3SVC10 for example.
Note also that you could do these changes manually by editing the site id attribute in the IIS config file on each server:
C:\Windows\System32\inetsrv\config\applicationHost.config . Requires admin privs and still needs a reset afterwards.