I am making a website to simply administrate but I cannot manage to log the user out, I am using cookies to verify the user. When I try to asynchronously log the user out it says "page not found". This is what ive come up with:
[HttpPost]
public async Task<IActionResult> SignOutAsync()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return RedirectToAction("Index");
}
And in my .cshtml file:
@if (User.Identity.IsAuthenticated)
{
<p>Hello, @User.Identity.Name</p>
<a onclick="document.getElementById('logout_form').submit();" style="cursor: pointer;">
Sign out
</a>
<form asp-controller="Home" asp-action="SignOutAsync" method="post" id="logout_form"></form>
}
else
{
<a asp-controller="Home" asp-action="Login">Sign in</a>
}