Managing user roles

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

Getting users who belong to the given role

 

[C#]

 

using CMS.SiteProvider;

 

// Get role of specified name from current site

RoleInfo role = CMS.SiteProvider.RoleInfoProvider.GetRoleInfo("ArticleEditor", CMS.CMSHelper.CMSContext.CurrentSiteName);

 

if (role != null)

{

  // Get datatable of the role members

  DataTable users = CMS.SiteProvider.RoleInfoProvider.GetRoleUsers(role.RoleID);

 

  if (users != null)

  {

     // the table now contains the users that belong to the given role ...

  }

}

 

 

Get user's roles

 

[C#]

 

using CMS.SiteProvider;

 

// Get UserInfo of the specified name

UserInfo user = CMS.SiteProvider.UserInfoProvider.GetUserInfo("Alice");

 

if (user != null)

{

  // Get table with all user roles

  DataTable table = CMS.SiteProvider.UserInfoProvider.GetUserRoles(user.UserID);

 

  if (table != null)

  {

    // the table now contains the roles the user is member of...

  }

}

 

 

Adding user to role

 

[C#]

 

// Use UserName, RoleName and SiteName to add user to role

CMS.SiteProvider.UserInfoProvider.AddUserToRole("Alice", "DocumentEditor", CMS.CMSHelper.CMSContext.CurrentSiteName);

 

 

Removing user from role

 

[C#]

 

// Use UserName, RoleName and SiteName to remove user from role

CMS.SiteProvider.UserInfoProvider.RemoveUserFromRole("Alice", "DocumentEditor", CMS.CMSHelper.CMSContext.CurrentSiteName);

 

 

Checking if user is member of a given role

 

See Checking user permissions for more details.

 

Page url: http://devnet.kentico.com/docs/devguide/index.html?managing_user_roles.htm