More in this section

Forums / General Discussions / How to get sitefinity built in roles programmatically

How to get sitefinity built in roles programmatically

3 posts, 0 answered
  1. Doug
    Doug avatar
    34 posts
    Registered:
    20 Sep 2010
    13 Jan 2011
    Link to this post
    Hey all,

    The following code is some test code that I've put into a user control to experiment with.
    01.protected void SubmitButton_Click(object sender, EventArgs e)
    02.{
    03.     // Get membership user
    04.     User user = (User)Membership.GetUser(UserNameTextBox.Text, true);
    05. 
    06.     // Get Sitefinity role manager
    07.     var roleManager = RoleManager.GetManager();
    08. 
    09.     // Get all roles
    10.     var roles = roleManager.GetRoles().ToList();
    11. 
    12.     // Get all roles for a particular user
    13.     var rolesForUser = roleManager.GetRolesForUser(user.Id).ToList();
    14. 
    15.     // Putting this into a string for simple testing and spitting out to an asp:Label
    16.     string strRoles = string.Empty;
    17. 
    18.     int i = 0;
    19.     foreach (Role role in rolesForUser)
    20.     {
    21.          bool printComma = i != rolesForUser.Count() - 1;
    22.          strRoles += role.ToString();
    23.          strRoles += printComma ? ", " : string.Empty;
    24. 
    25.          i++;
    26.     }
    27. 
    28.     string data = string.Format("information [user: {0}, creation_date: {1}, roles: {2}]", user.UserName, user.CreationDate.ToString(), strRoles);
    29.     LabelDisplay.Text = data;   
    30.}

    Why is 'roleManager.GetRoles()' only returning roles I've created and not the five default roles included with an install of Sitefinity?

    The default roles I'm speaking of is: 'Administrators', 'Authors', 'Editors', 'BackendUsers', 'Designers' which is not be retuirned by the 'roleManager.GetRoles()'.

    Any reasons why this would occur?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    13 Jan 2011
    Link to this post
    Hello Doug,

    I think that this is explained in this post.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Doug
    Doug avatar
    34 posts
    Registered:
    20 Sep 2010
    13 Jan 2011
    Link to this post
    Thanks
3 posts, 0 answered