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);
}
}
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.
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??
Hi raza,
have you tried:
ie pass in the id, and the path (as csv of ids) for the test for the Member having access ?
regards
Marc
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.
Yes, Path is not an obvious name for what it is, and you immediately think 'file path' !!
glad it's working now.
regards
Marc
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.