Programatically get pages for roles

Posted by Community Admin on 05-Aug-2018 09:13

Programatically get pages for roles

All Replies

Posted by Community Admin on 03-Jan-2012 00:00

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.

Posted by Community Admin on 03-Jan-2012 00:00

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

Posted by Community Admin on 24-Mar-2015 00:00

Hi Ancuta Me,

 There is any way to get pages for User.

Thanks 

 

 

This thread is closed