2012-11-11 27 views
1

我在两个不同的asp.net web应用程序中共享会话变量。使用web.config共享会话状态不反射

我正在使用“StateServer”模式。

对于共享,我设置_appDomainAppId的的httpRuntime相同的用于使用反射的应用程序。在的Application_Start功能,这里是我的代码:

  string applicationName = "mysite" 

      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); 

这里是我的问题:我不想使用反射此。我想在web.config中处理这个。

有什么办法可以在web.config中设置_appDomainAppId?我在httpRuntime部分或其他地方找不到任何东西。

谢谢。

回答

0

_appDomainAppdId的访问对应的是AppDomainAppId。初始化后没有提供手动设置AppDomainAppId的方法。 (该属性为只读。)

对于共享会话状态,您需要使用不同的会话状态提供程序。您可以在此选项,会话状态服务,SQL或自定义选项之间进行选择。

讨论了用于共享状态的SQL会话状态提供者的黑客攻击here。 (从2007年,但我在这看着最近(2017年),它仍然适用。)

建立一个自定义会话状态提供讨论here