Asp.Net StateServer实现共同域名下Session共享
2017-03-09 12:16
513 查看
概述
在实验的时候,参照了多方的信息,确实成功了,这里简单记录一下。
我们知道,在Asp.Net的Web.Config文件中,System.Web节点下,有个sessionState节点,它说明了应用程序的Session处理方式,它有如下几个选项:
View Code
第三步:将自定义HttpModule加入Web.config
参考文档
http://sai5d.blog.163.com/blog/static/62225483201010211393132/ https://msdn.microsoft.com/zh-cn/library/h6bb9cz9(VS.80).aspx
在实验的时候,参照了多方的信息,确实成功了,这里简单记录一下。
我们知道,在Asp.Net的Web.Config文件中,System.Web节点下,有个sessionState节点,它说明了应用程序的Session处理方式,它有如下几个选项:
public class ShareSessionModule : IHttpModule { #region IHttpModule 成¨¦员 void IHttpModule.Dispose() { //throw new Exception("The method or operation is not implemented."); } void IHttpModule.Init(HttpApplication context) { //throw new Exception("The method or operation is not implemented."); 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, ".test.com"); context.EndRequest += new EventHandler(this.EndRequest); } private void EndRequest(object sender, EventArgs args) { HttpApplication application = sender as HttpApplication; for (int i = 0; i < application.Response.Cookies.Count; i++) { application.Response.Cookies[i].Domain = ".test.com"; } } #endregion }
View Code
第三步:将自定义HttpModule加入Web.config
<httpModules> <add name="CookieTest" type="WebApplication1. ShareSessionModule,WebApplication1"/> </httpModules>
参考文档
http://sai5d.blog.163.com/blog/static/62225483201010211393132/ https://msdn.microsoft.com/zh-cn/library/h6bb9cz9(VS.80).aspx
相关文章推荐
- 通过ASP.NET StateServer实现进程外Session存储
- 说说Asp.net的StateServer和Session共享
- asp.net基于StateServer的二级域名共享session
- ASP.NET 负载均衡 StateServer Session共享问题(经验记录)
- asp.net session共享(通过StateServer方式)
- 使用ASP.NET State Server实现多应用程序间共享Session State
- asp.net session共享(通过StateServer方式)
- asp.net 跨网站/应用程序池/虚拟目录/域名 的Session共享解决方案
- 转之农民伯伯 IHttpHandler中使用Session实现原理[ASP.NET | IHttpHandler |IRequiresSessionState]
- 如何实现Asp与Asp.Net共享Session
- ASP.NET sessionState设置Mode为StateServer,报出Internal Server Error
- 如何实现Asp与Asp.Net共享Session
- Asp.net 实现Session分布式储存(Redis,Mongodb,Mysql等) sessionState Custom
- ASP.NET存储Session的StateServer
- 如何实现Asp与Asp.Net共享Session
- ASP.NET存储Session的StateServer
- 如何实现Asp与Asp.Net共享Session
- 实现Asp与Asp.Net共享Session的方法
- 如何实现Asp与Asp.Net共享Session
- 如何实现Asp与Asp.Net共享Session