Reading cookie value in asp.net core

I have a problem reading cookies. In the first request, I add a cookie with a method

Response.Cookies.Append("UserName", "Name", new Microsoft.AspNetCore.Http.CookieOptions()
        {
            Path = "/",
            HttpOnly = false,
            Secure = false
        });

In the next query, I want to read the value from cookies

 var name = Request.Cookies["UserName"]

but Request.Cookies is null. But also when I call this method by typing api in the browser

localhost:5555/api/tempController/getCurrenUserName

var name = Request.Cookies ["UserName"] returns me a value, and Request.Cookies contains all the cookies that I see in the browser.

I do not understand why in one case it works in another, it does not work.

+4
source share
1 answer

the problem was the fetch method in knockout.js, I replaced it with jQuery methods and now it works !!!

0
source

Source: https://habr.com/ru/post/1671708/


All Articles