More in this section
Forums / Sitefinity SDK / Programatically get pages for roles

Programatically get pages for roles

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 0 answered
  1. Ancuta Me
    Ancuta Me avatar
    43 posts
    26 Apr 2010
    03 Jan 2012
    Link to this post

    I have a problem when trying to get the pages for a specific user role.
    I have 4 types of roles and more than 13 pages in total, on a basic hierarchy with 2 levels. These are the pages for my main navigation and I want it to be different fr every user role.

    I want to use this from outside the Sitefinity app, so I make use of the role's name, like this:

    ArrayList listOfRoles = new ArrayList();
    var siteNode = App.WorkWith().Pages().Get().Where(p => p.Parent == null && p.Title == "Pages").Single();

    listOfRoles.Add(SecurityManager.GetRoleId("AppRoles", "Everyone"));
    listOfRoles.Add(SecurityManager.GetRoleId("AppRoles", "MyRoleHere"));

    Guid[] listOfRolesGuids = new Guid[listOfRoles.Count];
                listOfRolesGuids = listOfRoles.ToArray(typeof(Guid)) as Guid[];

                SecurityConfig cfg = Config.Get<SecurityConfig>();
                var permSet = cfg.Permissions[SecurityConstants.Sets.Pages.SetName];
                int actionMask = permSet.Actions[SecurityConstants.Sets.Pages.View].Value;

    var firstLevelPages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).
                        .Where(p => p.ShowInNavigation == true)
                       .Where(p => p.IsGranted(SecurityConstants.Sets.Pages.SetName, listOfRolesGuids, actionMask))
                        .OrderBy(p => p.Ordinal)

    Somehow, I end up with 2 different results, one when I am logged in as an admin, the other when I'm not.
    Is there a way to bypass this? I would like to get the pages regardless of the cookies on my browser.

    Any help or hint will be greatly appreciated, thanks.
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    02 Jan 2018
    03 Jan 2012
    Link to this post
    Hi Ancuta Me,

    Actually it's normal for the results to vary based on the currently logged user, as we're doing an internal security check that will return only the pages that the currently logged user has permissions over. If you still need to get the pages and bypass the security check you can set SuppressSecurityChecks property of the PageManager.Provider to true.

    Boyan Barnev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. shan
    shan avatar
    1 posts
    24 Mar 2015
    24 Mar 2015
    Link to this post

    Hi Ancuta Me,

     There is any way to get pages for User.




3 posts, 0 answered