Cross Domain Cookies Problem (ASP.NET)

Posted by Laserson on Stack Overflow See other posts from Stack Overflow or by Laserson
Published on 2010-04-26T17:04:41Z Indexed on 2010/04/26 17:13 UTC
Read the original article Hit count: 154

Filed under:
|
|
|
|

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??

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about cookie