Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • raza 15 posts 115 karma points
    Jul 17, 2016 @ 23:42
    raza
    0

    Programmatic Determination if Member has access?

    I'm trying to get published content to display as links to content pages in a site footer partial, but it can only be for content the logged in member has access to. I'm having trouble figuring out what I need to use to determine this. I've tried a couple of different methods (even though one of them is deprecated) and neither are working.

    One of the content items I'm querying for, I've applied role-based permissions to via BackOffice. Then when I log in as a user that is NOT in one of the allowed roles, the code below is still giving ALL of the records to display. However, if while still logged into the site as that same member, I can't navigate to that protected content. I get redirected to the Not Authorized page I configured. So I know the public access is applied.

    What am I doing wrong here??

        var highlights = umbracoHelper.TypedContent(parentNodeId).Children
                        .Where(c => !c.GetPropertyValue<bool>("archivedHighlight"))
                                    .OrderByDescending(c => c.GetPropertyValue<DateTime>("highlightDate")).ToList();
    
     foreach (var highlight in highlights)
                {    
                    if (ApplicationContext.Current.Services.PublicAccessService.HasAccess(highlight.Url, Membership.GetUser(), Roles.Provider))
                    {
                        // I've also tried UmbracoHelper.MemberHasAccess(highlight.Url) and I get the same results as using PublicAccessService.HasAccess
                        highlightCollection.Add(highlight);                       
                    }                
                }
    
  • Marc Goodson 2149 posts 14377 karma points MVP 9x c-trib
    Jul 17, 2016 @ 23:51
    Marc Goodson
    1

    Hi raza,

    have you tried:

     foreach (var highlight in highlights)
                {    
                    if (Umbraco.MemberHasAccess(hightlight.Id,highlight.Path)
                    {
                        highlightCollection.Add(highlight);
                        count++;
                    }                
                }
    

    ie pass in the id, and the path (as csv of ids) for the test for the Member having access ?

    regards

    Marc

  • raza 15 posts 115 karma points
    Jul 17, 2016 @ 23:52
    raza
    0

    Oh geez!!!!!!!! I just figured out that the "path" parameter to HasAccess() method wasn't referring to a URL path, but instead was expecting the node path! (highlight.Path). I'm laughing at myself for this, but will leave this here in case someone has a senior moment like I just did.

  • Marc Goodson 2149 posts 14377 karma points MVP 9x c-trib
    Jul 18, 2016 @ 09:10
    Marc Goodson
    0

    Yes, Path is not an obvious name for what it is, and you immediately think 'file path' !!

    glad it's working now.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft