It’s been quite a while since I last posted cos I have been quite busy lately. Anyway, I had a problem where I wanted to share session state between http and https pages (example between http://www.mysite.com and https://secure.mysite.com). Naturally, in this case, the webserver will give you a different session id because the session id is bound to the domain.
I managed to share the state by overwriting the sessionid cookie “ASP.NET_SessionId” of subdomain pages with the sessionId of the main site. However, in order for this to work you have to also change the domain property of the cookie to be that of the main site. The code is dead simple:
Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID;
Response.Cookies["ASP.NET_SessionId"].Domain = WebConfigurationManager.AppSettings["CookieDomain"].ToString();
If you do not change the domain property, the cookie will not be read properly on subdomain pages. However, for security reasons, this solution does not work across different domains since you cannot write cookies for domains that are different than the current one.

