Thursday, October 11, 2007

Sharing ASP.NET Sessions accross subdomains

Put this code in Global.asax as part of Application_Request

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

This will rewrite the session cookie so that it can be retrieved accross sub domains.  This is particularly useful when you are switching from www.domain.com to domain.com (same site, different urls) where you would otherwise loose the session variables even though they are still available.

del.icio.us Tags: , ,
Technorati Tags: , ,

0 comments: