Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Session State Is Lost in Web Farm If You Use SqlServer or StateServer Session Mode


View products that this article applies to.

Symptoms

If you use SqlServer or StateServer session state mode, session state may be lost when you run an ASP.NET Web application in a load balanced Web farm environment.

↑ Back to the top


Cause

To maintain session state across different Web servers in the Web farm, the application path of the Web site (for example, \LM\W3SVC\2) in the Microsoft Internet Information Services (IIS) metabase must be the same for all of the Web servers in the Web farm. The case also needs to be the same because the application path is case-sensitive.

On one Web server, the instance ID of the Web site where the ASP.NET application is hosted may be 2 (where the application path is \LM\W3SVC\2). On another Web server, the instance ID of the Web site may be 3 (where the application path is \LM\W3SVC\3). Therefore, the application paths between Web servers in the Web farm are different. For additional information about how to check the application path of the Web site, click the following article number to view the article in the Microsoft Knowledge Base:
240225 Description of Adsutil and MetaEdit Used to Modify the Metabase

↑ Back to the top


Resolution

To work around this problem, synchronize the application path for the Web site in the IIS metabase for all Web servers in the Web farm. Make sure that the case is the same since the application path for the Web site is case-sensitive.

Note Microsoft recommends that you back up the IIS metabase before you change the metabase. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
302573 HOW TO: Back Up and Restore IIS
To synchronize the application path of the Web site, use one of the following methods:
  • Modify the IIS metabase by using code.
    1. Create a text file, and then name the file Moveinstance.vbs.
    2. Add the following script code to Moveinstance.vbs, which modifies the instance IDs of the Web sites so that they are the same:
      Dim WebService
      Dim oldstr
      Dim newstr
      Dim args
      Set args = WScript.Arguments
      If args.Count < 1 Then
          Wscript.Echo "Must have original instance id and new instance id" &     chr(10) & chr(13) & _
          "usage:  moveinstance.vbs 1 5"  & chr(10) & chr(13) & _
      "Moves instance 1 to instance 5"
          WScript.Quit()
      End If
      Set WebService = GetObject("IIS://LocalHost/W3SVC")
      oldstr = args(0) 'old instance
      newstr = args(1) 'new instance
      WebService.MoveHere oldstr,newstr
      WebService.SetInfo
      Set WebService = nothing
      Set args=nothing
      WScript.echo "DONE"
      						
    3. Save Moveinstance.vbs.
    4. Run the script from a command prompt from the same location that you saved the .vbs file in the previous step.

      For example, type cscript moveinstance.vbs 1 5 at the command prompt. This changes the instance ID of a Web site from 1 to 5 in the metabase.

      Note Make sure that the new instance ID that you assign to the Web site is not already assigned to another Web site. This may lead to unreliable results.
  • Modify the metabase to synchronize the application path of the Web site by using any of the tools that are described in Microsoft Knowledge Base article Q240225. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
    240225 Description of Adsutil and MetaEdit Utilities Used to Modify the Metabase
Note When you use StateServer mode, make sure that the <machineKey> section has the same keys in the Machine.config file across the Web farm. For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
312906 HOW TO: Create Keys by Using Visual C# .NET for Use in Forms Authentication
313091 HOW TO: Create Keys by Using Visual Basic .NET for Use in Forms Authentication

↑ Back to the top


Keywords: KB325056, kbstate, kbprb, kbconfig

↑ Back to the top

Article Info
Article ID : 325056
Revision : 6
Created on : 10/29/2003
Published on : 10/29/2003
Exists online : False
Views : 602