1

I am trying to set a cookie for domain b.com, but the page which is setting the cookie is on a.com

the code is as below

HttpCookie myCookie = new HttpCookie("UserSettings");
myCookie["Font"] = "Arial";
myCookie["Color"] = "Blue";
myCookie.Expires = DateTime.Now.AddDays(1d);
myCookie.domain = "b.com";
myCookie.path ="/";
Response.Cookies.Add(myCookie);

I'm pretty sure this part of the code is working as I am able to do a request.cookies to get the values. However, it is not really set on my browser. When I open a browser (such as Chrome and Firefox) and view all the cookies, then search for domain "b.com", nothing is found! Is the cookie is not really set? I tried all night to figure this out but I can't. What am I doing wrong?

Sumner Evans
  • 8,551
  • 5
  • 29
  • 46
onegun
  • 798
  • 1
  • 9
  • 25
  • 1
    That sounds like it shouldn't work. I don't think you can change cookies on domains other than your own... It seems like a security risk to me. – Sumner Evans Apr 13 '15 at 02:39
  • anyway for me to set for other domain, i also doubt this is the problem, but i hope there is a way to solve. i am not thinking to hack other site, but need to do something on my company intranet sites. – onegun Apr 13 '15 at 02:42

1 Answers1

2

As stated in this question, there is no way to create a cookie for a different domain. If it's possible for you, you could work your way with redirections from domain to domain to set the cookies.

Community
  • 1
  • 1
Phil-R
  • 2,183
  • 17
  • 20