set cookie options when deleting a cookie?
This commit is contained in:
parent
693004bcb9
commit
0235a4c52b
1 changed files with 23 additions and 2 deletions
|
@ -62,7 +62,28 @@ internal static class HttpContextSessionExtensions
|
||||||
|
|
||||||
public static void DeleteSession(this HttpContext httpContext)
|
public static void DeleteSession(this HttpContext httpContext)
|
||||||
{
|
{
|
||||||
httpContext.Response.Cookies.Delete("session");
|
var cookieSettings = httpContext.RequestServices.GetService<IOptions<CookieSettings>>();
|
||||||
httpContext.Response.Cookies.Delete("user");
|
|
||||||
|
var secure = cookieSettings?.Value.Secure ?? true;
|
||||||
|
var sameSite = secure ? SameSiteMode.None : SameSiteMode.Unspecified;
|
||||||
|
var domain = cookieSettings?.Value.Domain;
|
||||||
|
|
||||||
|
httpContext.Response.Cookies.Delete("session", new CookieOptions
|
||||||
|
{
|
||||||
|
HttpOnly = true,
|
||||||
|
Domain = domain,
|
||||||
|
IsEssential = true,
|
||||||
|
Secure = secure,
|
||||||
|
SameSite = sameSite,
|
||||||
|
Expires = DateTimeOffset.UtcNow.AddDays(-1),
|
||||||
|
});
|
||||||
|
httpContext.Response.Cookies.Delete("user", new CookieOptions
|
||||||
|
{
|
||||||
|
Domain = domain,
|
||||||
|
IsEssential = true,
|
||||||
|
Secure = secure,
|
||||||
|
SameSite = sameSite,
|
||||||
|
Expires = DateTimeOffset.UtcNow.AddDays(-1),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue