asp.net 多站点共享StateServer Session

  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的域名要设置相同的域名

时间: 2024-08-10 15:11:33

asp.net 多站点共享StateServer Session的相关文章

asp.net 多站点共享FormAuthentication

<authentication mode="Forms"> <forms  domain="lizhanglong.com" timeout="2880" /> </authentication> <machineKey decryptionKey="*" validationKey="*" validation="SHA1" decryptio

.net多站点通过StateServer实现session共享

先在所有要共享站点web.config的<system.web>结点下加 <!--session的mode=StateServer--><sessionState cookieless="false" timeout="50" mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424"/><!--机器码要统一--&g

ASP.NET二级域名站点共享Session状态

前面一篇文章提到了如何在使用了ASP.NET form authentication的二级站点之间共享登陆状态, http://www.cnblogs.com/jzywh/archive/2007/09/23/902905.html, 今天, 我要写的是如何在二级域名站点之间,主站点和二级域名站点之间共享Session. 首先, Session要共享,站点之间SessionID必须要一致,那怎么保证SessionID一致呢? ASP.NET中的SessionID是存储在客户端的cookie之中键

nginx 负载均衡、用数据库存储Session,来实现多站点共享Session[转]

多站点共享Session常见的作法有: 1.使用.net自动的状态服务(Asp.net State Service); 2.使用.net的Session数据库: 3.使用Memcached. 4.使用Cookie方式实现多个站点间的共享(这种方式只限于几个站点都在同一域名的情况下): 这里我们就 演练一下 以数据库的形来存储Session,来实现多站点共享Session. 首先我们 建好一下站点,如下图: Default.aspx 其中 有二个Button  ,SetSession 主要是用于给

【转】asp.net中利用session对象传递、共享数据[session用法]

来自:http://blog.unvs.cn/archives/session-transfer-method.html 下面介绍Asp.net中利用session对象传递.共享数据用法: 1.传递值: 首先定义将一个文本值或单独一个值赋予session,如下: session["name"]=textbox1.text:将文本1的值赋给了session变量name,当调查到其它页面时,此值可以传递,依然存在,下面是调用或判断此值. If(session["name"

多站点共享Session

多站点共享Session 多站点共享Session有很多方法,多站点共享Session常见的做法有: 使用.net自动的状态服务(Asp.net State Service); 使用.net的Session数据库: 使用Redis等缓存. 使用Cookie方式实现多个站点间的共享,但是这种方式只限于几个站点都在同一域名的情况下: 这里主要介绍数据库的形式存储Session,来实现多站点共享Session. 1.新建web站点,添加setSession.aspx 等页面,如下图: 2.修改web.

Asp.net mvc与PHP的Session共享的实现

最近在做的一个ASP.NET MVC的项目,要用到第三方的php系统,为了实现两个系统的互联互通.决定将两者的session打通共享.让asp.net mvc 和php 都能正常访问和修改Session内容. 在决定实现之前,先搜索了一下院子里有没有相类似的文章,对于跨语言的程序互通,有两种方案: (1)       SSO单点登录,其实就是把用户名和密码传给另一个系统在另一个系统上自动创建session 来解决. (2)       还有就是用同一套Session,在数据库或缓存上架设sess

android如何与asp.net服务端共享session

近期需要实现一个功能,就是需要通过发送短信进行注册,现在想把短信验证码放到服务器的session值中,当客户端收到短信并提交短信码时由asp.net服务端进行判断,那么如何共享这个session那么需要在android客户端中添加几行代码.如下操作.第一次数据请求时就获取这个cookie的名称并且得到这个cookie的值,这个即是sessionid的值并保存在一个静态变量中,然后在第二次请求数据的时候要将这个sessionid一并放在Cookie中发给服务器,服务器则是通过这个sessionid

ASP.NET MVC单点登录(多站点共享用户信息)

一.多站点共享用户信息解决方案: 采用分布式缓存Memcache模拟Session进行用户信息信息共享 1.视图部分 @{ Layout = null; } <!DOCTYPE html> <html> <head> <title>XX商城后台管理系统登录</title> <script type="text/javascript"> if (window.parent.window != window) { wi