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

Forums / Sitefinity SDK / Programatically get pages for roles

Programatically get pages for roles

3 posts, 0 answered
  1. Ancuta Me
    Ancuta Me avatar
    43 posts
    Registered:
    26 Apr 2010
    03 Jan 2012
    Link to this post
    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.
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    02 Dec 2016
    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.

    Regards,
    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
    Registered:
    24 Mar 2015
    24 Mar 2015
    Link to this post

    Hi Ancuta Me,

     There is any way to get pages for User.

    Thanks 

     

     

3 posts, 0 answered