asp.net网站不同子域名共享session信息
来源:互联网 发布:淘宝奇葩买家秀大尺度 编辑:程序博客网 时间:2024/05/17 04:32
1session信息可序列化 [Serializable]
[Serializable] public class UserSession { public string GroupCode { get; set; } public string RoleCode { get; set; } }
2 使cookie的path为根域名而不是子域名
function setCookie(name, value) {//两个参数,一个是cookie的名子,一个是值 var Days = 30; //此 cookie 将被保存 30 天 var exp = new Date(); //new Date("December 31, 9998"); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString()+"; path=/"; }
3开启服务aspnet_state.exe
4修改web.config的sessionState
<!--<sessionState mode="InProc" cookieless="false" timeout="600" />--> <sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" timeout="60"></sessionState>
5修改Global.asax文件
在 void Session_Start(object sender, EventArgs e)中添加调用如下代码
private void InitSession() { foreach (string moduleName in this.Modules) { string appName = "APPNAME"; IHttpModule module = this.Modules[moduleName]; SessionStateModule ssm = module as SessionStateModule; if (ssm != null) { System.Reflection.FieldInfo storeInfo = typeof(SessionStateModule).GetField("_store", System.Reflection.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); } } } } if (Response.Cookies != null) { for (int i = 0; i < Response.Cookies.Count; i++) { if (Response.Cookies[i].Name == "ASP.NET_SessionId") { Response.Cookies[i].Domain = ".dhcc.com.cn"; //一定要保持不同应用程序的"ASP.NET_SessionId"的cookie的Domain值一致 } } } }
void Session_Start(object sender, EventArgs e) { InitSession();}
阅读全文
0 0
- asp.net网站不同子域名共享session信息
- ASP.NET中在不同的子域中共享Session(二级域名获取不到主域名下的session值)
- ASP.NET实现多域名多网站共享Session值
- ASP.NET实现多域名多网站共享Session值
- ASP.NET中在不同的子域中共享Session
- ASP.NET中在不同的子域中共享Session
- ASP.NET中在不同的子域中共享Session
- asp.net 跨网站/应用程序池/虚拟目录/域名 的Session共享解决方案
- php子域名共享session
- 跨域名(跨服务器)共享SESSION ASP.NET 解决方案
- Spring-session & redis 子域名共享session
- 不同的asp.net web应用程序间共享Session/Application
- 同一服务器不同域名session共享
- asp.net Session 共享
- Asp.net session共享
- 多子域名下,SESSION共享设定
- ASP.NET Forms验证 实现子域名(SubDomain)共享登陆下的缺陷
- asp和asp.net共享session解决办法
- java 插入新的数组项(算法—1)
- JDBC连接数据库
- 一个判断session是否过期的小技巧
- AngularJS入门-(2)MVC体系结构
- Java中try,catch,finally的用法
- asp.net网站不同子域名共享session信息
- nodejs express request 和 response 对象分析
- Bootstrap笔记
- Java并发编程之CyclicBarrier
- 搭载web服务器
- 原生二维码扫描
- mybatis的config.xml文件中不再需要通过<mapper>一个一个配置实体的xml文件了
- shiro页面前端获取当前用户信息
- LBS相关工具函数