Код: Выделить всё
contextAccessor.HttpContext?.Response.Cookies.Append("MyKey", userToken,
new CookieOptions
{
Expires = DateTime.UtcNow.AddHours(5),
HttpOnly = true,
Secure = true,
IsEssential = true,
SameSite = SameSiteMode.None
});
Код: Выделить всё
public void LogOut() => contextAccessor.HttpContext?.Response.Cookies.Delete("MyKey");
Код: Выделить всё
public static string? GetToken(this IHttpContextAccessor contextAccessor)
{
try
{
return contextAccessor.HttpContext!.Request.Cookies.FirstOrDefault(x => x.Key == "MyKey").Value;
}
catch
{
return null;
}
}
Я' Я прочитал этот вопрос и этот другой, и в ответе говорится о создании двух токенов. Это должно работать правильно, но это означает, что я не могу удалить файл cookie HttpOnly?
Моя версия .NET — 8.0
Подробнее здесь: https://stackoverflow.com/questions/782 ... only-token