Synchronizing the Application Path of a Web Site
Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1
If you use SqlServer or StateServer session state mode, session state might be lost when you run an ASP.NET Web application in a Network Load Balancing server cluster. To maintain session state across different Web servers in the cluster, the application path of the Web site (for example, \LM\W3SVC\2) in the IIS metabase must be the same for all of the Web servers in the cluster.
You can change the Web site instance ID by manually editing the metabase on each Web server or by using the script Moveinstance.vbs as described in this section. For more information about manually editing the IIS metabase, see Working with the Metabase.
You must be a member of the Administrators group on the local computer to run scripts and executables. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run your script or executable as an administrator. At a command prompt, type runas /profile /user:MyComputer</STRONG>Administrator cmd to open a command window with administrator rights and then type cscript.exe ScriptName (include the script's full path and any known parameters).
To synchronize the application path of a Web site
Create a text file, and then name the file Moveinstance.vbs.
Add the following script code to Moveinstance.vbs. This code 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"
From the same directory in which you saved Moveinstance.vbs, run the script from a command prompt. For example, at the command prompt, type the following:
cscript moveinstance.vbs 1 5
and then press ENTER. This changes the instance ID of a Web site from 1 to 5 in the metabase.
When you use StateServer mode, make sure that the [machineKey] section in the Machine.config file has the same keys on every server in the Web farm.
For more information about session state and ASP.NET Web applications, see Preserving Session State with ASP.NET Web Applications in Network Load Balancing.