0

I want to read Cookies from my Angular Application which is set in this way in Angular this.cookieService.set('KeepMeLoggedIn', String(this.checkBoxValue));
in .NET Framework 4.8 API. I tried multiple options to read value like this way
Request.Cookies["KeepMeLoggedIn"]
or like it is described in documentation here but it still always return null.
I've checked In DevTools and the cookie is set before trying to read value and it's set.

Was the cookie set wrong/needs to be sent in a diffrent way or how should I read the value in API?

elmazurro
  • 1
  • 1
  • In DevTools can you check the request to the API? Is the cookie transmitted to the server? If not, is domain and/or path of the cookie correct? – Markus Apr 07 '22 at 09:44
  • can you share cookieService.set() code? Also, the header of the request sent to API in DevTools network tab have that cookie? – J.Salas Apr 07 '22 at 09:44
  • @Markus cookie domain and path is set correct but I saw that it's not transmitted to the server. Should be cookie sent in a header? – elmazurro Apr 07 '22 at 10:38
  • Yes, cookies are transmitted to the server in the header of the request - if domain and path match. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies for details. Does the domain of the API match the domain of the website? AFAIK you can only create cookies in javascript for the same domain, e.g. www.example.com (and its ancestors, *.example.com). For cross-domain, you need to create the cookie from the server: https://stackoverflow.com/a/31074655/642579 – Markus Apr 08 '22 at 06:24

0 Answers0