码迷,mamicode.com
首页 > Web开发 > 详细

asp.net 多站点共享StateServer Session

时间:2016-04-10 18:01:39      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

  1. <sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="false" ></sessionState>

  2. 打开注册表,运行cmd/regedit,找到节点HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\aspnet_state\Parameters

      a.将AllowRemoteConnection值设置为1

      b.将Port值设置为a5b8(十六进制),即十进制42424(默认值)

  3. 分别在网站项目A和网站项目B的Global.asax.cs中加入下面代码
    public override void Init()
            {
                base.Init();
                foreach (string moduleName in this.Modules)
                {
                    string appName = "APPNAME";
                    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);
                            }
                        }
                    }
                }
            }
    

      ASP.NET_SessionId Cookie的域名要设置相同的域名

asp.net 多站点共享StateServer Session

标签:

原文地址:http://www.cnblogs.com/lizhanglong/p/5374584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!