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

时间:2013-07-20 04:33:35

标签: asp.net subdomain

如何维护子域之间的会话。我在非锻炼之下尝试了

httpCookies domain =“。site.com”

FTP中的我的文件夹结构

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.

任何人都可以告诉我如何维护这些子域之间的会话。

1 个答案:

答案 0 :(得分:1)

使用这个我希望它对你有用。

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    

}