Programatically get pages for roles - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Programatically get pages for roles

  • Programatically get pages for roles
  • Hi,

    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).
                        ThatArePublished()
                        .ThatBelongTo(siteNode.Id)
                        .Where(p => p.ShowInNavigation == true)
                       .Where(p => p.IsGranted(SecurityConstants.Sets.Pages.SetName, listOfRolesGuids, actionMask))
                        .OrderBy(p => p.Ordinal)
                       .Get().ToList();

    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.
  • 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.

    Regards,
    Boyan Barnev
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  • Hi Ancuta Me,

     There is any way to get pages for User.

    Thanks