惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - 布瓜去旅行

适时放手,是对自己的尊重 PhoneGap初试! 【转】Swift之 ? 和 ! 一场空欢喜 不要悲伤,我亲爱的好姑娘 更新证书错误:No matching provisioning profiles found CABasicAnimation的基本使用方法(移动·旋转·放大·缩小) iPhone4S出现应用无法打开时的解决方案 [转] XCode 4.2 新功能 - Storyboard [摘] Objective-C的self.用法的一些总结 C# winform 与 flash as 的交互通讯 IE6中正确显示png图片 【转】DD_belatedPNG,解决IE6不支持PNG绝佳方案 IE6中margin值双倍的解决方案 [转] 弹性+固宽布局 Windows2003下配置PHP环境 去除Visual Studio .NET工程同SourceSafe的关联 遭遇价格欺诈 塑料瓶底的标志的含义!
ASP.NET中解决跨子域的Session共享
布瓜去旅行 · 2012-07-19 · via 博客园 - 布瓜去旅行

原文地址:http://www.itivy.com/ivy/archive/2011/4/24/634392360221984930.html

新建一个类库项目,添加以下类:

using System.Web; 
using System; 
using System.Configuration; 
using System.Diagnostics; 
using System.Reflection; 
using System.Web.SessionState;   

namespace WebLibrary 
{
     public class CrossDomainCookie : IHttpModule
     {
         private string m_RootDomain = string.Empty;

         #region IHttpModule Members
         public void Dispose() 
         {  
         } 
         public void Init(HttpApplication context)
         {
             m_RootDomain = ConfigurationManager.AppSettings["RootDomain"];
             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, m_RootDomain); 

             context.EndRequest += new System.EventHandler(context_EndRequest);
         }
         void context_EndRequest(object sender, System.EventArgs e)
         {
             HttpApplication app = sender as HttpApplication;
             for (int i = 0; i < app.Context.Response.Cookies.Count; i++)
             {
                 app.Context.Response.Cookies[i].Domain = m_RootDomain; 
             }
         }
         #endregion
     }
 } 

把它编译成dll。

然后在每个需要共享session的网站项目中做以下几件事情:

1、引用上面的dll

2、在web.config的appsetting节点中添加你的主站域名

<add key="RootDomain" value=".itivy.com"/> 


3、在web.config的system.web节点中添加

<httpModules>
    <add name="CrossDomainCookieModule" type="WebLibrary.CrossDomainCookie, WebLibrary"/> 
</httpModules>


 4、在web.config的system.web节点中修改session存储方式为stateserver

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" timeout="30" /> 


5、在web.config的system.webServer几点中添加

<modules>
    <add name="CrossDomainCookieModule" preCondition="managedHandler" type="WebLibrary.CrossDomainCookie, WebLibrary"/> 
</modules>