Rajeesh Menoth
Rajeesh Menoth

Reputation: 1750

How to share session state across subdomains

I have two websites with domains www.example.com and www.test.example.com both contain same student details. I want to share session between the two domains.Is it possible?

Upvotes: 2

Views: 1892

Answers (1)

Vishal
Vishal

Reputation: 171

Use following method:

void MasterPage_Unload(object sender, EventArgs e)
{
   ///ASP.NET uses one cookie per subdomain/domain,
   ///we need one cookie for _all_ subdomains.
   if (Context.Response.Cookies["ASP.NET_SessionId"] == null)
      return;

   var sessionCookie = new HttpCookie("ASP.NET_SessionId", Context.Session.SessionID);
   sessionCookie.Domain = ".yourdomain.com" ; 
   Context.Response.SetCookie(sessionCookie);
 }

Upvotes: 1

Related Questions