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

推荐订阅源

V
V2EX
W
WeLiveSecurity
IT之家
IT之家
A
About on SuperTechFans
B
Blog
L
LangChain Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
Google Online Security Blog
Google Online Security Blog
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
Schneier on Security
Schneier on Security
GbyAI
GbyAI
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
Cloudbric
Cloudbric
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
S
Security Affairs
The Last Watchdog
The Last Watchdog
H
Heimdal Security Blog
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Privacy & Cybersecurity Law Blog
V
Visual Studio Blog
H
Hacker News: Front Page
Recorded Future
Recorded Future
Cyberwarzone
Cyberwarzone
L
Lohrmann on Cybersecurity
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
Jina AI
Jina AI
N
News | PayPal Newsroom
S
Schneier on Security

博客园 - 布瓜去旅行

适时放手,是对自己的尊重 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>