当我点击 razor 组件 LoginDisplay.razor 中的注销按钮时,它会导航但不会转到 MyApplication.Areas.Identity.Pages.Account 中的 Logout.cshtml.cs
public async Task<IActionResult> OnPost(string returnUrl = null)
{
.... // doesn't come over here
}
startup.cs
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
LoginDisplay.razor
<AuthorizeView>
<Authorized>
<a href="Identity/Account/Manage">Hello, @context.User.Identity.Name!</a>
<form method="post" action="Identity/Account/LogOut">
<button type="submit" class="nav-link btn btn-link">Log out</button>
</form>
</Authorized>
<NotAuthorized>
<a href="Identity/Account/Register">Register</a>
<a href="Identity/Account/Login">Log in</a>
</NotAuthorized>
当我点击注销按钮时,输出是:
答案 0 :(得分:0)
也许尝试恢复到原始 LogOut.cshtml 版本 - 没有任何 LogOut.cshtml.cs,以查看您自定义的 LogOut 页面中是否存在问题。
我的整个 LogOut.cshtml 如下所示,并使用您的确切代码:
@page
@using Microsoft.AspNetCore.Identity
@attribute [IgnoreAntiforgeryToken]
@inject SignInManager<ApplicationUser> SignInManager //Could be IdentityUser instead of ApplicationUser
@functions {
public async Task<IActionResult> OnPost()
{
if (SignInManager.IsSignedIn(User))
{
await SignInManager.SignOutAsync();
}
return Redirect("~/Identity/Account/Login");
}
}