How to create persistent Cookie from HttpContext's Cookie.Append method?

Mahesh Kumar 65 Reputation points
2024-12-13T09:39:45.98+00:00
var token = await _jwtTokenService.GenerateToken(user);
HttpContext.Response.Cookies.Append("accessToken", token, new CookieOptions
{
    HttpOnly = true,
    Expires = DateTime.UtcNow.AddHours(1),
    SameSite = SameSiteMode.None,
    Secure = false,
    IsEssential = true,
    
});

I am attaching the token in Cookie with the help of HttpContext

I can't find a way to make it persistent . Right now, on refreshing the page, the cookie is destroyed automatically. I want it to stay in the browser ever after closing the page until its expiry date. How do i do it?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,734 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.