与会话状态服务器共享会话
Sharing session with session state server
我正在尝试在 varnish round robin 负载平衡器之间设置两个 Windowz 框(win1
、win2
)。
应用程序的会话状态均配置为 "State server" 指向第三台计算机 (x.y.w.z
)。 win1
和 win2
都可以调用 telnet x.y.w.z 42424
。
Al 机器具有相同的 OS 版本。
两台机器都有相同的机器密钥
我已经放入了从 http://pardini.net/blog/2011/02/17/the-ultimate-asp-net-session-state-debugging-tool/ 复制的 ans aspx 调试页面,它显示了两个不同的机器密钥。
我可以看出AppDomainAppId
不一样;我该如何改变它?
这里发生了什么?
按照 Sharing session state over multiple ASP.NET applications with ASP.NET state server 中的建议,我在 Global.aspx.cs
中添加了一个挂钩
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;
using NHibernate.Mapping.Attributes;
using System.Web.SessionState;
using System.Reflection;
/// <summary>
/// Summary description for Global
/// </summary>
public class Global : System.Web.HttpApplication
{
public static ISessionFactory SessionFactory;
private static Configuration _configuration;
public override void Init()
{
base.Init();
foreach (string moduleName in this.Modules)
{
string appName = "MYAPPNAME";
IHttpModule module = this.Modules[moduleName];
SessionStateModule ssm = module as SessionStateModule;
if (ssm != null)
{
FieldInfo storeInfo = typeof(SessionStateModule).GetField("_store", BindingFlags.Instance | BindingFlags.NonPublic);
SessionStateStoreProviderBase store = (SessionStateStoreProviderBase)storeInfo.GetValue(ssm);
if (store == null) //In IIS7 Integrated mode, module.Init() is called later
{
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, appName);
}
else
{
Type storeType = store.GetType();
if (storeType.Name.Equals("OutOfProcSessionStateStore"))
{
FieldInfo uribaseInfo = storeType.GetField("s_uribase", BindingFlags.Static | BindingFlags.NonPublic);
uribaseInfo.SetValue(storeType, appName);
}
}
}
}
}
(...)
我正在尝试在 varnish round robin 负载平衡器之间设置两个 Windowz 框(win1
、win2
)。
应用程序的会话状态均配置为 "State server" 指向第三台计算机 (x.y.w.z
)。 win1
和 win2
都可以调用 telnet x.y.w.z 42424
。
Al 机器具有相同的 OS 版本。
两台机器都有相同的机器密钥
我已经放入了从 http://pardini.net/blog/2011/02/17/the-ultimate-asp-net-session-state-debugging-tool/ 复制的 ans aspx 调试页面,它显示了两个不同的机器密钥。
我可以看出AppDomainAppId
不一样;我该如何改变它?
这里发生了什么?
按照 Sharing session state over multiple ASP.NET applications with ASP.NET state server 中的建议,我在 Global.aspx.cs
中添加了一个挂钩using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;
using NHibernate.Mapping.Attributes;
using System.Web.SessionState;
using System.Reflection;
/// <summary>
/// Summary description for Global
/// </summary>
public class Global : System.Web.HttpApplication
{
public static ISessionFactory SessionFactory;
private static Configuration _configuration;
public override void Init()
{
base.Init();
foreach (string moduleName in this.Modules)
{
string appName = "MYAPPNAME";
IHttpModule module = this.Modules[moduleName];
SessionStateModule ssm = module as SessionStateModule;
if (ssm != null)
{
FieldInfo storeInfo = typeof(SessionStateModule).GetField("_store", BindingFlags.Instance | BindingFlags.NonPublic);
SessionStateStoreProviderBase store = (SessionStateStoreProviderBase)storeInfo.GetValue(ssm);
if (store == null) //In IIS7 Integrated mode, module.Init() is called later
{
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, appName);
}
else
{
Type storeType = store.GetType();
if (storeType.Name.Equals("OutOfProcSessionStateStore"))
{
FieldInfo uribaseInfo = storeType.GetField("s_uribase", BindingFlags.Static | BindingFlags.NonPublic);
uribaseInfo.SetValue(storeType, appName);
}
}
}
}
}
(...)