Search code examples
c#.netumbracoumbraco8

Umbraco - LogOut Backoffie user in umbracoApiController


i am having an issue with logging out a Backoffice user.

The usecase is that i am manually logging out the user by setting the users jwt token expiration day to now, and then i would like to log out the user from the umbraco backoffice if logged in.

Below is the code for my logout method.

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

The User remains signed into the backoffice. Is there anyone that can help me with signing the user out of the backoffice ?


Solution

  • In your post you are talking about logging out of the back office, while using the Members.Logout() which is for the members.

    To log out backoffice users you need to use the UserService

    I have tested it and if you know the userID then you can use the

    Services.UserService.ClearLoginSessions(int userID)
    

    To find the userID you could use the

    Services.UserService.GetByUsername(string username)
    

    method. (But maybe there is a better option in your case.)

    More information about UserService