I try to add cookies to the response in a ASP.NET Core 3.1 Web Application. The issue is that the cookie is not appended to the response.This is the code:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!\n");
string cookieValueFromContext = context.Request.Cookies["hello"];
await context.Response.WriteAsync($"Response: {cookieValueFromContext}");
context.Response.Cookies.Append("hello", "cookie", new CookieOptions
{
MaxAge = TimeSpan.FromDays(10),
IsEssential = true
});
await context.Response.WriteAsync("Ending");
});
});
}
And this is what I see in browser:
I tried to debug the application the debug stops at the append cookie method, no exception is raised. Message Ending is not displayed. In browser (Chrome) no cookie is stored, I checked Application/Cookies, not even after reload. From my knowledge I do not need to add Cookie Policy Option if the cookie is set as essential. From what I read on other posts the browser might choose which cookies to consider essential, even if you set it as essential. Could this be the case ?

Aucun commentaire:
Enregistrer un commentaire