15

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:

  1. Our setup is 2 x Load balanced WebServers + single session state database.
  2. 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.
  3. 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).
  4. 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.

Full instructions:

  1. Remote Desktop onto server LIVE1, open IIS Mgr, click on the problem Site and choose Advanced Settings in the sidebar.
  2. Change the ID to something unique e.g. 10. Click OK.
  3. Restart the web service (c:\windows\system32\iisreset /restart)

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.

1 Answer 1

12

Judging by your question it seems that you have a central session state server (DB?) that keeps track of the session data?

You must also synchronize the machine key which is used for encryption for any forms authentication etc to work. This might also affect the session identification, I'm not sure.

Configuring Machine Keys in IIS 7

Furthermore, you should make use of the shared configuration between the machines, it might itself fix the issue with different machine keys.

IIS Configuration Synchronization for Web Server Farm?

EDIT: When you changed the site ID, did you try to restart IIS manager to see if the webroot had changed? Maybe the configuration is connected to the ID meaning that a change in ID also modifies stuff like the document root etc

4
  • Thanks for the ideas Jishi but I had already synced the machineKey in the web.configs. I guess I'm really looking at a way of changing a site's IIS Instance ID without having to completely remove and reconfigure the sites on the web servers. Jul 11, 2011 at 13:21
  • When you changed the site ID, did you try to restart IIS manager to see if the webroot had changed? Maybe the configuration is connected to the ID meaning that a change in ID also modifies stuff like the document root etc.
    – jishi
    Jul 11, 2011 at 14:14
  • 2
    Yep, that was it! I forgot to restart the IIS service (command line iisreset /restart). Worked fine after that! Please update you answer with this info and I will give you the Accepted Answer. Jul 11, 2011 at 14:16
  • Done deal. Glad it worked out for you.
    – jishi
    Jul 11, 2011 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .