I'm trying to control access to certain pages via role-based authentication, and everything works fine except I'm having a hard time finding how to hide children of a page (in a partial view) if the member doesn't have access to those children.
For instance, I can type (strongly in this case):
@foreach(var item in Model.Content.Children.Where(item => item.IsVisible())
It will show pages that the user doesn't have authentication for. I'm looking to hide the page if the user doesn't have the authentication to see it, and I can't seem to find anything in examples or documentation (granted I haven't read through it all) that would work out of the box for a partial view page. Is there something like this or would I have to change my approach altogether?
There is an Umbraco Helper Method called 'MemberHasAccess' that you can use when writing out the children to determine if the current member has access to the pages.
Only show children according to authentication
I'm trying to control access to certain pages via role-based authentication, and everything works fine except I'm having a hard time finding how to hide children of a page (in a partial view) if the member doesn't have access to those children.
For instance, I can type (strongly in this case):
It will show pages that the user doesn't have authentication for. I'm looking to hide the page if the user doesn't have the authentication to see it, and I can't seem to find anything in examples or documentation (granted I haven't read through it all) that would work out of the box for a partial view page. Is there something like this or would I have to change my approach altogether?
Hi Jackson
There is an Umbraco Helper Method called 'MemberHasAccess' that you can use when writing out the children to determine if the current member has access to the pages.
Umbraco.MemberHasAccess(page.Id, page.Path)
https://our.umbraco.org/documentation/reference/querying/umbracohelper/
your foreach loop would become:
regards
Marc
Thanks Marc, works great. I'll take a look at Umbraco Helper Methods in the future before I ask.
FYI for anyone else with this issue, Umbraco.MemberHasAccess(item.Id,item.Path) is obsolete; put Umbraco.MemberHasAccess(item.Path) instead.
is working on a reply...