使用 Azure AD 登录时,我无法从 .Net core Web 应用程序注销。
当我尝试使用不同的电子邮件登录时,它只是以之前登录的用户身份登录。当新用户尝试登录时,它甚至不会要求输入密码。
我尝试了以下方法,但是 -
// Send an OpenID Connect sign-out request.
HttpContext.GetOwinContext().Authentication.SignOut(
OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
OR
HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
or
if (HttpContext.User.Identity.IsAuthenticated)
{
await HttpContext.Authentication.SignOutAsync(settings.SignInPolicyId);
await HttpContext.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}
这些都不适用于 .Net Core。
下面的代码在 .net core 上构建并运行,但它不会完全注销用户。
Request.GetOwinContext().Authentication.SignOut(new AuthenticationProperties { RedirectUri = clsCommonFunction.GetLoginURL() });
请帮忙。
最佳答案
Here是 ASP.NET Core 的 SignOut 方法。
[HttpGet]
public IActionResult SignOut()
{
var callbackUrl = Url.Action(nameof(SignedOut), "Account", values: null, protocol: Request.Scheme);
return SignOut(
new AuthenticationProperties { RedirectUri = callbackUrl },
CookieAuthenticationDefaults.AuthenticationScheme,
OpenIdConnectDefaults.AuthenticationScheme);
}
[HttpGet]
public IActionResult SignedOut()
{
if (User.Identity.IsAuthenticated)
{
// Redirect to home page if the user is authenticated.
return RedirectToAction(nameof(HomeController.Index), "Home");
}
return View();
}
Its not even asking for password when the new user is trying to login.
请清除浏览器缓存Ctrl+F5。
关于azure - 无法在 .Net Core Web 应用程序上使用 Azure AD 身份验证注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50630863/