在每个站点上,web.config包含StateServer和相同的machineKey:
<sessionState mode="StateServer" stateConnectionString="tcpip=STATESRV01:42424" />
<machineKey decryptionKey="EDCDA6DF458176504BBCC720B4E29348E252E652591179E2" validationKey="CC482ED6B5D3569819B3C8F07AC3FA855B2FED7F0130F55D8405597C796457A2F5162D35C69B61F257DB5EFE6BC4F6CEBDD23A4112C4519F55185CB5EB3DFE61"/>
Run Code Online (Sandbox Code Playgroud)
我们还有一个PostRequestHandlerExecute事件处理程序来修改"NET_SessionId"cookie以具有相同的根域和路径.
cookie.Domain = ".mysite.local";
cookie.Path = "/";
Run Code Online (Sandbox Code Playgroud)
在global.asax文件中,我们有以下代码来修改Application_Start事件中的App Name:
protected void Application_Start(object sender, EventArgs e)
{
string applicationName = "mysiteapp";
// Change the Application Name in runtime.
FieldInfo runtimeInfo = typeof(HttpRuntime).GetField("_theRuntime",
BindingFlags.Static | BindingFlags.NonPublic);
HttpRuntime theRuntime = (HttpRuntime)runtimeInfo.GetValue(null);
FieldInfo appNameInfo = typeof(HttpRuntime).GetField("_appDomainAppId",
BindingFlags.Instance | BindingFlags.NonPublic);
appNameInfo.SetValue(theRuntime, applicationName);
}
Run Code Online (Sandbox Code Playgroud)
两个站点都返回相同的会话ID,但是当我们尝试在site1上设置会话值时,site2不会返回值.
站点1(site1.mysite.local)结果
Session ID (Session.SessionID): a55jnfcscxd3f0hnwoik02pp
Session Value: True
Run Code Online (Sandbox Code Playgroud)
站点2(site2.mysite.local)结果
Session ID (Session.SessionID): a55jnfcscxd3f0hnwoik02pp …Run Code Online (Sandbox Code Playgroud)