【发布时间】:2021-06-09 19:41:22
【问题描述】:
我正在制作一个网站来简单地管理,但我无法将用户注销,我正在使用 cookie 来验证用户。当我尝试异步注销用户时,它说“找不到页面”。这是我想出的:
[HttpPost]
public async Task<IActionResult> SignOutAsync()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return RedirectToAction("Index");
}
在我的 .cshtml 文件中:
@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>
}
【问题讨论】:
标签: c# asp.net-core asp.net-core-mvc