API Questions on Kentico API.
Version 5.x > API > Checking a user's role View modes: 
User avatar
Guest
jhart - 9/30/2013 5:13:25 PM
   
Checking a user's role
So I am using this if statement to check if a user is of a specific role:
if (CMS.CMSHelper.CMSContext.CurrentUser.IsInRole("ServiceRep", CMS.CMSHelper.CMSContext.CurrentSite.SiteName))
{
//do stuff
}

ServiceRep is a custom role I created. When I test this with a user that is of this role, I get a false. I made sure the role was added to the user. When I use this to check all of the users roles
var roles = CMS.SiteProvider.UserInfoProvider.GetUserRoles(CMS.CMSHelper.CMSContext.CurrentUser);

if (roles != null)
{
foreach (var role in roles.Rows)
{

}

}

The the only roles that show up are Everyone and unauthenticated.

User avatar
Member
Member
kentico_sandroj - 9/30/2013 5:28:38 PM
   
RE:Checking a user's role
Hello,

Are the user and role assigned to that specific site? Also, what is the hotfix version for this site? I will attempt to reproduce the issue once I have this information.

Best Regards,
Sandro

User avatar
Guest
jhart - 10/1/2013 7:44:10 AM
   
RE:Checking a user's role
The user and role are applied to the site. The site is using v5.5.3803

User avatar
Guest
jhart - 10/1/2013 10:10:39 AM
   
RE:Checking a user's role
I have been stepping through the code and when I looked closely at the current user, it says the current user is not the Global Administrator, which is what i am logged in as. It says the current user is someone whose username is public.

User avatar
Guest
jhart - 10/1/2013 2:49:02 PM
   
RE:Checking a user's role
I found a solution. I was trying to get the current users information while inside of a control. As soon as i moved it into the page that calls the controls, I had no issues.