0

How can we access cookie created by one domain in another domain.

I have created cookie as following in one domain

Response.Cookies["newOne"].Value = "something";

from another domain I am accessing it as

var data = Request.Cookies["newOne"].Value; //This is throwing exception

I am able to access cookie from local but not from another domain.

Chakri
  • 770
  • 2
  • 7
  • 24

3 Answers3

0

Give your cookie domain name also as shown :-

   Response.Cookies["newOne"].Value = "something";
   Response.Cookies["newOne"].Domain = ".mydomain.com"

and then access its value in other domain.

Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
0

HttpCookie hcookie = new HttpCookie("cookiename","Cookie Value"); hcookie.Domain = ".example.com";

Please try this link http://msdn.microsoft.com/en-us/library/dd920298(v=vs.95).aspx

USER87
  • 547
  • 5
  • 3
0

This question's pretty cold, but in case anyone else stumbling on it, or the OP still has need, I've created an NPM module, which allows you to share locally-stored data across domains:

By using an iframe hosted on Domain A, you can store all of your user data on Domain A, and reference that data by posting requests to the Domain A iframe.

Thus, Domains B, C, etc. can inject the iframe and post requests to it to store and access the desired data. Domain A becomes the hub for all shared data.

With a domain whitelist inside of Domain A, you can ensure only your dependent sites can access the data on Domain A.

The trick is to have the code inside of the iframe on Domain A which is able to recognize which data is being requested. The README in the above NPM module goes more in depth into the procedure.

Hope this helps!

jmealy
  • 583
  • 1
  • 5
  • 14