在非核心 asp mvc 应用程序中,我有一个用于全局注销用户的 Controller 操作
看起来像这样
public ActionResult Logout()
{
Request.GetOwinContext().Authentication.SignOut();
return Redirect("/");
}
现在我有一个 asp 核心客户端,想要注销我试过了
public async Task<ActionResult> LogOut()
{
if (User.Identity.IsAuthenticated)
{
await HttpContext.Authentication.SignOutAsync("Cookies");
}
return Redirect("/");
}
更新
现在我好像注销了,但我被重定向到一个需要身份验证的站点。 我可以看到我很快又被重定向到身份服务器,它会自动再次让我进入。
总结: 我在我的 asp 应用程序中注销了,但没有在身份服务器上注销。
如何全局注销?所以我需要在身份服务器上退出?
最佳答案
如果您使用OpenIdConnect
身份验证,您还需要远程注销。尝试更改您的代码,如下所示:
public async Task<ActionResult> LogOut()
{
if (User.Identity.IsAuthenticated)
{
await HttpContext.Authentication.SignOutAsync("Cookies");
await context.Authentication.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties()
{
RedirectUri = "<signed out url>"
});
// if you use different scheme name for openid authentication, use below code
//await context.Authentication.SignOutAsync(<your openid scheme>, new AuthenticationProperties()
//{
// RedirectUri = "/signedout"
//});
}
return Redirect("/");
}
查看原始样本 https://github.com/aspnet/Security/blob/dev/samples/OpenIdConnectSample/Startup.cs
关于asp.net - 使用 IdentityServer 的 Asp Core 客户端全局注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40161504/