'asp.net cookies not set into browser
I am trying receive cookies in ASP.NET core API. When I am testing it in postman everything is working, but browser does not sends cookies back.
This is c# code which sets cookie in response.
HttpContext.Response.Cookies.Append("Test", "test value", new CookieOptions()
{
HttpOnly = false,
Domain = "localhost",
Expires = DateTimeOffset.Now.AddDays(10),
IsEssential = true,
Path = "/",
Secure = false,
SameSite = SameSiteMode.Strict,
MaxAge = TimeSpan.MaxValue
});
Here is js code
var myHeaders = new Headers();
myHeaders.append("Accept", "application/json");
myHeaders.append("credentials", "include");
var requestOptions = {
method: 'GET',
headers: myHeaders
};
fetch("https://localhost:5001/api/user/get-authed-user", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
During debugging asp.net, there is not "Test" cookie in it when sending request from browser.
Postman does it well and the "Test" cookie is visible during debugging.
Also I can not see cookies in browser (F12 -> Application -> cookies).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
