Umbraco - 在 umbracoApiController 中注销 Backoffie 用户

Umbraco - LogOut Backoffie user in umbracoApiController

我在注销 Backoffice 用户时遇到问题。

用例是我通过将用户 jwt 令牌到期日设置为现在手动注销用户,然后如果登录,我想从 umbraco 后台注销用户。

下面是我的注销方法的代码。

[HttpPost]
[Route("logout")]
public void LogOut()
{
    HttpContext.Current.Response.Cookies["token"].Expires = DateTime.Now;
    Members.Logout();
    FormsAuthentication.SignOut();
}

用户仍然登录后台。有没有人可以帮助我将用户从后台注销?

在您的 post 中,您正在谈论退出后台,同时使用 Members.Logout() 供会员使用。

要注销后台用户,您需要使用 UserService

我已经测试过了,如果你知道用户 ID,那么你可以使用

Services.UserService.ClearLoginSessions(int userID)

要查找用户 ID,您可以使用

Services.UserService.GetByUsername(string username)

方法。 (但也许您的情况有更好的选择。)

More information about UserService