发布时间: 2012-06-20 20:37:21 作者: rapoo
在不同的二级域名下Session共享的问题解决
首先看看webconfig的配置
分两种情况,具体配置看下面的
web.config配置如下:IIS6: //****************************////create date:2010-01-11//****************************//namespace YeWenBin.Web{ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.SessionState; using System.Reflection; /// <summary> /// 二级域名会话共享 继承IHttpModule /// </summary> public class SessionSharedHttpModule : IHttpModule { string _rootDomain = null; //一级域名 public void Dispose() { //throw new NotImplementedException(); } public void Init(HttpApplication context) { _rootDomain = "yewenbin.cn"; //一级域名赋值 //去除一级域名以外信息(将www.yewenbin.cn改为yewenbin.cn,如果一级域名不是常量赋值的话) //_rootDomain = _rootDomain.Substring(_rootDomain.LastIndexOf('.', _rootDomain.LastIndexOf('.') - 1) + 1); //要实现会话共享还得修改OutOfProcSessionStateStore类下的一个私有的静态字段s_uribase //OutOfProcSessionStateStore的声明为: //internal sealed class OutOfProcSessionStateStore : SessionStateStoreProviderBase //s_uribase的声明为: //static string s_uribase; //关于OutOfProcSessionStateStore类以及s_uribase字段的内容请查阅OutOfProcStateClientManager.cs文件 //文件路径:Framework源代码\V2.0.5727\dd\ndp\fx\src\xsp\System\Web\State\OutOfProcStateClientManager.cs Type stateServerSessionProvider = typeof(HttpSessionState).Assembly.GetType("System.Web.SessionState.OutOfProcSessionStateStore"); FieldInfo uriField = stateServerSessionProvider.GetField("s_uribase", BindingFlags.Static | BindingFlags.NonPublic); if (uriField == null) throw new ArgumentException("UriField was not found"); uriField.SetValue(null, _rootDomain); context.EndRequest += new EventHandler(context_EndRequest); } /// <summary> /// 从发送给客户端的Cookie集合中找出记录会话ID的Cookie /// 并修改它的Domain属性值为要共享的一级域名 /// </summary> void context_EndRequest(object sender, System.EventArgs e) { HttpApplication app = sender as HttpApplication; for (int i = app.Context.Response.Cookies.Count - 1; i >= 0; i--) { //ASP.NET_SessionId是默认的存储会话ID的key,如果修改了默认值这里要修改成一致的 if (app.Context.Response.Cookies[i].Name.Equals("ASP.NET_SessionId")) { app.Context.Response.Cookies[i].Domain = _rootDomain; return; } } } }}
JAVA基础-java中ET的差异
ByteBuffer跟String的互相转换
vim 编辑器的三种模式怎么切换
电脑编码
地图reduce编程模型介绍
Java基础java缓存读写资料小例子
学习jar下令 创建和解压jar文件包
java生成随机数、四舍五入、当前时间的
[猖獗Java讲义精粹] 第十一章|多线程
Java Thread 小结