Clarify how cookies are working between Angular and c# controller

Viewed 23

I would like to clarify how cookies work between angular app and the c# server controller. This is what I gathered from various discussions and forums:

  1. The angular client sends HTTP Request (e.g. to login) to the c# server

  2. c# server creates the cookie (e.g. refreshToken) using:

    Response.Cookies.Append("refreshToken", token, cookieOptions);

  3. c# server returns and the cookie refreshToken is set in store on the client side

  4. Whenever the angular client sends the HTTP request again, the cookie is set in the Request object (probably by the browser, behind the scenes - angular client does not explicitly set the cookie)

  5. c# server receives the request and retrieves the cookie like below:

    var refreshToken = Request.Cookies["refreshToken"];

Is my understanding correct?

1 Answers

Yes, your understanding is totally correct. One note: Angular HttpClient does only include cookies for cross-domain requests (like in dev environment) in the request if HttpOption withCredentials is set to true.

Related