Search code examples
angularcookiessession-cookiesc#-3.0asp.net-core-3.1

I don't see the added cookie. And it is not sent to the server


I add a cookie and expect it to come in requests. But I don't see it in the browser, and it doesn't come back in requests.

The client side uses the latest version of angular. Post type request. Do I understand correctly that cookies should be added automatically ?

On server side i add it as follows:

context.Response.Cookies.Append(CookieName, data, new CookieOptions
        {
            Secure = True,
            HttpOnly = true,
            SameSite = SameSiteMode.None,
            Path = "/",
            IsEssential = true,
        });

After requesting the server I see the set-cookie command in the header: s

But I don't see the cookie itself (although the browser indicates that there is 1 cookie).

dont see the cookie

Also i don't see a cookie being sent with a request dont see the cookie

UPD: Also tried SameSite=Lax + Secure=false. The cookie is not saved.


Solution

  • It looks like you're setting SameSite=None without the Secure attribute with the Secure = false in your configuration. A cookie with SameSite=None must include Secure.

    If you open Chrome DeveloperTools and look at the Issues tab you should be able to see more information about the cookie that has problems and what to do to address it. Your second screenshot is actually showing that your site is using LocalStorage not a cookie.