1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Assigning Application Roles

Assigning Application Roles

3 posts, 1 answered
  1. Anders
    Anders avatar
    5 posts
    Registered:
    29 Apr 2011
    05 Jul 2011
    Link to this post
    Does anyone know how I can via the API assign a user the roles like "Editors" or "Authors"?

    Using the RoleManager.GetManager().GetRole("Editors") is not supported. So one can't call the AddUserToRole() method.

    I can't find my way around the documentation and pinpoint the proper keyword to search for.
    The one thing I keep hitting is this:

    "application roles – these are similar to user roles, but they are assigned to

    users automatically based on predefined conditions."

    But no clues as to what those conditions are. I can set the roles via the GUI, but I need to do it through code.

     

    Any help is most welcome.

    .a

     

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    05 Jul 2011
    Link to this post
    Hello Anders,

    Here is a sample code

    RoleManager roleManager = RoleManager.GetManager("AppRoles");
    roleManager.Provider.SuppressSecurityChecks = true;
    var role = roleManager.GetRole("Administrators");// or any other AppRole
    roleManager.AddUserToRole(user, role);
    roleManager.SaveChanges();


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Anders
    Anders avatar
    5 posts
    Registered:
    29 Apr 2011
    05 Jul 2011
    Link to this post
    Thank you for a quick response!

    .a
3 posts, 1 answered