Cross Domain Cookies Problem (ASP.NET)

10,178

Solution 1

You can check if the cookie headers are being returned by the browser by using a web debugger such as fiddler.

It will show you the headers and cookies sent for every request and response, so you can see if the correct domain has been set and what happens with the request to the second domain.

Solution 2

Hmm...The problem was in browser...Opera browser doesn't send cookie to other site on the same subdomain. Firefox and IE works great. Anyway, thank you guys!

Some notes: if you want remove such cookie from other subdomain then you need to set a Domain property to something like: .mydomain.com - i've spend a lot of time by trying to figure it out. Hope it helps for somebody

Solution 3

In IIS 7

Add this to your web.config

<system.webserver>
    <httpProtocol>
        <customHeaders>
            <add name="p3p" value="CP=&quot;NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM&quot;" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

In II6.

  • Run inetmgr
  • Expand [Server] > Web Sites
  • Right clic in [Your site]
  • Properties
  • HTTP Headers
  • Add...
  • Custom header name: p3p
  • Custom header value: CP="NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM"
  • OK
  • OK
Share:
10,178
Laserson
Author by

Laserson

Software Developer

Updated on June 04, 2022

Comments

  • Laserson
    Laserson about 2 years

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