ASP.NET Session State, Cookies and Subdomains


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
  2.  
  3. {
  4.  
  5. /// only apply session cookie persistence to requests requiring session information
  6.  
  7.  
  8.  
  9. #region session cookie
  10.  
  11. if (Context.Handler is IRequiresSessionState || Context.Handler is IReadOnlySessionState )
  12.  
  13. {
  14.  
  15. /// Ensure ASP.NET Session Cookies are accessible throughout the subdomains.
  16.  
  17.  
  18.  
  19. if (Request.Cookies["ASP.NET_SessionId"] != null && Session != null && Session.SessionID != null)
  20.  
  21. {
  22.  
  23. Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID;
  24.  
  25. Response.Cookies["ASP.NET_SessionId"].Domain = ".know24.net"; // the full stop prefix denotes all sub domains
  26.  
  27. Response.Cookies["ASP.NET_SessionId"].Path = "/"; //default session cookie path root
  28.  
  29. }
  30.  
  31. }
  32.  
  33. #endregion
  34.  
  35. }

URL: http://www.know24.net/blog/ASPNET+Session+State+Cookies+And+Subdomains.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.