码迷,mamicode.com
首页 > Web开发 > 详细

asp.net 二级域名session共享

时间:2015-04-12 01:10:49      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

1.自定义类

namespace SessionShare
{
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
}
}
2.web.config中添加如下内容
<appSettings>
    <!--Session共享域名-->
    <add key="RootDomain" value=".session.com"/>
  </appSettings>
<system.web>
    <machineKey decryptionKey="FD69B2EB9A11E3063518F1932E314E4AA1577BF0B824F369" validationKey="5F32295C31223A362286DD5777916FCD0FD2A8EF882783FD3E29AB1FCDFE931F8FA45A8E468B7A40269E50A748778CBB8DB2262D44A86BBCEA96DCA46CBC05C3" validation="SHA1" decryption="Auto"/>
    <sessionState cookieless="false" timeout="50" mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424"/>
<httpModules>
            <add name="CrossDomainCookieModule" type="SessionShare.CrossDomainCookie,SessionShare"/>
    </httpModules>
</system.web>
<system.webServer>
<modules>
            <add name="CrossDomainCookieModule" type="SessionShare.CrossDomainCookie,SessionShare"/>
    </modules>
</system.webServer>
3.修改C:\WINDOWS\system32\drivers\etc\hosts文件(hosts文件做ip映射)
注:两个网站都要添加.

 

asp.net 二级域名session共享

标签:

原文地址:http://www.cnblogs.com/tiancai/p/4418775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!