Cross Domain Cookies Problem (ASP.NET)
- by Laserson
Hi guys, i have a problem with cross-domain cookies. I read a lot of documentation about sharing cookies between subdomains. The main idea of all articles is set Domain property to something like ".mydomain.com". I've created two domains on local IIS server - test1.local.boo and test2.local.boo. They works great and visible with browser. I have the following code:
Site test1 - Writes cookie:
HttpCookie myCookie = new HttpCookie("TestCookie");
myCookie.Domain = ".local.boo";
myCookie["msg"] = "Welcome from Cookie";
Response.Cookies.Add(myCookie);
Site test2 - Reads cookie:
HttpCookie cookie = Request.Cookies["TestCookie"];
if (cookie != null)
{
Response.Write(cookie["msg"]);
}
else
{
Response.Write("FAILED");
}
This code always shows FAILED message. So it means that second site can't read cookie from the same subdomain. Where is my mistake??