zoukankan      html  css  js  c++  java
  • asp.net 二级域名session共享

    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:WINDOWSsystem32driversetchosts文件(hosts文件做ip映射)
    注:两个网站都要添加.
  • 相关阅读:
    nVelocity .NET的模板引擎(template engine) 转载
    NewWords/700800
    美剧字幕杀手之王第1季 第1集
    美剧字幕傲骨贤妻第1季 第1集
    NewWords/9001000
    示例代码控制设备背景代码
    算法把图像压缩成指定大小的代码
    获取和设置 iphone 屏幕亮度
    美剧字幕傲骨贤妻第1季 第2集
    NewWords/600700
  • 原文地址:https://www.cnblogs.com/tiancai/p/4418775.html
Copyright © 2011-2022 走看看