【问题标题】:Sharing session with session state server与会话状态服务器共享会话
【发布时间】:2016-06-17 11:04:52
【问题描述】:

我正在尝试在清漆循环 loab 平衡器之间设置两个 Windowz 框(win1、win2)。

应用程序的会话状态都配置为“状态服务器”,指向第三台机器 (x.y.w.z)。从win1 和win2 都可以调用telnet x.y.w.z 42424。 所有机器都有相同的操作系统版本。 两台机器有相同的机器密钥

我已经进入从http://pardini.net/blog/2011/02/17/the-ultimate-asp-net-session-state-debugging-tool/ 复制的 ans aspx 调试页面,它显示了两个不同的机器密钥。

我可以看到AppDomainAppId 不同;我怎样才能改变它? 这里发生了什么?

【问题讨论】:

    标签: windows iis-7 cluster-computing session-state


    【解决方案1】:

    正如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);
                    }
                }
            }
        }
    }
    (...)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-20
      • 2011-02-21
      • 2018-05-18
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      相关资源
      最近更新 更多