.NET 2級ドメイン名共有セッション

7600 ワード

ASP.NET        Session  
    ,                 ,              Session。
    , Session   ,    SessionID     ,     SessionID   ?
  ASP.NET  SessionID        cookie     ASP.NET_SessionId       Session          ,           ,            SessionID      ,          ASP.NET_SessionId  cookie   。
  A: CrossDomainCookieModule
  ------------------------------------------------------------------------------------------------
  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"];
   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
  }
     Module     cookie domain root domain, root domain web.config   。                    cookie domain,          cookie name,    ASP.NET_SessionId     。
                   ,       ,  session      ,  Session ID    ,  Session       。
                     ,           。
                 ,        :
  1)      state server   Session.
  2)       web.config     machineKey.
  <machineKey
  validationKey="78AE3850338BFADCE59D8DDF58C9E4518E7510149C46142D7AAD7F1AD49D95D4"
  decryptionKey="5FC88DFC24EA123C"
  validation="SHA1"/>
  MachineKey      http://msdn.microsoft.com/zh-cn/asp.net/w8h3skw9.aspx
  3)          name
               siteID  ,siteID site name hash ,           ,       siteID  site name hash.
                  ,   CrossDomainCookie      ,                     :
  1)      state server   Session.
  2)       System.Web.SessionState.OutOfProcSessionStateStore     s_uribase  
  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
   }
                Session    。
          SQL server   Session,              Session    。

  :Diy     .NET      Session