简体   繁体   English

如何维护两个子域之间的会话?

[英]How to maintain session between two sub domain?

How to maintain session between sub domains.i tried below its not workout 如何维护子域之间的会话。

httpCookies domain=".site.com" httpCookies domain =“。site.com”

My Folder structure in FTP FTP中的“我的文件夹”结构

site1 > main site a website project.app_code,bin,web.config site1>主站点一个网站project.app_code,bin,web.config

      Folder Subdomain1. here i have all files like bin,app_code,web.config etc.

      Folder Subdomain2. here also same.

Can any one give me an idea how to maintain session between those sub domains. 任何人都可以给我一个想法,如何维护这些子域之间的会话。

Use This I hope Its usefull for you. 使用它,我希望它对您有用。

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)

{

  /// only apply session cookie persistence to requests requiring session information



  #region session cookie

  if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState )

  {

    /// Ensure ASP.NET Session Cookies are accessible throughout the subdomains.



    if (Request.Cookies["ASP.NET_SessionId"] != null && Session != null && Session.SessionID != null)

    {

      Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID;

      Response.Cookies["ASP.NET_SessionId"].Domain = ".know24.net"; // the full stop prefix denotes all sub domains

      Response.Cookies["ASP.NET_SessionId"].Path = "/"; //default session cookie path root         

    }

  }

  #endregion    

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM