'Removing cookie on logout causing Server status code 400 netcore 6.0
I am attempting to remove the session cookie on logout, resulting in a 400 error.
LoginPartial.cshtml
@if(User.Identity.IsAuthenticated)
{
<form method="post" class="form-inline" asp-page="/Logout">
<button id="Button" type="submit" name="submit" formmethod="post" class="btn">Logout</button>
</form>
}else
{
<a class="btn btn-link" asp-page="/Login">Login</a>
}
and the Logout.cshtml.cs looks like this:
namespace WebApp.Pages
{
public class LogoutModel : PageModel
{
public async Task<IActionResult> OnPostAsync(){
await HttpContext.SignOutAsync("MyCookieAuth");
return RedirectToPage("../");
}
}
}
The Cookies and claims all work well, as well as the User Identify Authentication. (net6.0)
Solution 1:[1]
the Logout.cshtml.cs looks like this:
namespace WebApp.Pages
{
public class LogoutModel : PageModel
{
public async Task<IActionResult> OnPostAsync(){
await HttpContext.SignOutAsync();
HttpContext.Response.Cookies.Remove("MyCookieAuth");
return RedirectToPage("../");
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | HootanHT |