0

How to send cookies from account.domain.com to app.domain.com?

I am working on an authentication. I want to send cookies from account.domain.com to app.domain.com. The problem is, I can send cookies in the response header but the browser does not set the cookie. I can see in the network tab, cookies present in the response header.

I want to use these cookies across all sub-domains i.e *.domain.com

cookie sent from account.domain.com

 var cookie = new HttpCookie("key", "value");

     cookie.Domain = "domain.com";
     cookie.HttpOnly = true;
     cookie.Secure = true;
     cookie.SameSite = System.Web.SameSiteMode.None;
     cookie.Path = "/";

 System.Web.HttpContext.Current.Response.Cookies.Add(cookie);

 return Ok();

on the client side, I use javascript(Axios) to send them.

await axios("https://app.domain.com/endpoint", {withCredentials: true});

await axios("https://api.domain.com/endpoint", {withCredentials: true});

I want to send these cookies with every request so I can authenticate.

saud
  • 1
  • 1
  • Configure the cookie's path, domain etc (I think if you use domain.com as the path, it should work). Anyway, please post snippet of your code and someone will be able to help faster. – Sekhar Jun 23 '21 at 04:43
  • Do you set the Domain property of cookie before returning it to the browser? – Chetan Jun 23 '21 at 04:43
  • @ChetanRanpariya updated my question these are my configuration. the domain is a placeholder. – saud Jun 23 '21 at 04:49
  • Are you adding cookie to the response by doing `Response.Cookies.Add`? How are you trying to send cookies from browser to the other domain? It will be helpful if you share code which sends cookies to the browser and the code which sends cookies from browser to the other application and how the other application tries to read the cookie from the request? – Chetan Jun 23 '21 at 04:51
  • @Sekhar i update my quesion. – saud Jun 23 '21 at 04:52
  • @ChetanRanpariya quesion updated – saud Jun 23 '21 at 05:01
  • Does this answer your question? [Write cookies from subdomain and read from another subdomain without changing web.config](https://stackoverflow.com/questions/21831605/write-cookies-from-subdomain-and-read-from-another-subdomain-without-changing-we) – user700390 Jun 23 '21 at 05:58
  • See this question https://stackoverflow.com/questions/21831605/write-cookies-from-subdomain-and-read-from-another-subdomain-without-changing-we I think you need a leading "." on the domain (.e.g `cookie.Domain = ".domain.com"` – user700390 Jun 23 '21 at 05:59

0 Answers0