Try our conversational search powered by Generative AI!

Get User Roles in WebApi


Hi I am testing WebApi calls and I Wanted to proble users and their roles.

I can get all roles, and user data but how can I check what roles a user has?

This is a plugin so I can not know what type of role providers a consuming project could have. COuld be Default ones, could be OWIN. Could be something different.

public IHttpActionResult GetCurrentUserData(string userName)
  var virtualRoleRepository = (RolesRepository ?? ServiceLocator.Current.GetInstance<IVirtualRoleRepository>()).GetAllRoles();
  var user = EPiServerProfile.Get(userName);
  //var userRoles = ?????
  if (user == null)
    return NotFound();
  return Ok(user);
Edited, Feb 24, 2020 12:32

You can use UIRoleProvider.GetRolesForUser(userName)

the drawback is UIRoleProvider is in EPiServer.Shell.Security, i.e. EPiServer UI package 

Feb 24, 2020 12:40

Thank you! I dont know if the namespace will be a problem, i would assume not and hope it will not :)

Feb 24, 2020 12:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.