I'm trying to create a simple menu which will only show items that a user has access to.
For example, we have a website with a home page (public) and then two private sections A and B.
When the user is not logged in, I want to show the link to "home" only. When the user is logged in and has permission to access "section A" the menu should display "Section A".
I've seen a post about the function "WhereHasAccess()" from Umbraco 5, but can't seem to find anything about 6 or 7.
At the moment all I have is:
var menuItems = homePage.Children;
I thought I could have something like this:
var menuItems = homePage.Children.WhereHasAccess();
or:
var menuItems = homePage.Children.Where(x => x.WhereHasAccess());
But neither option works at all.
Please can someone point me in the right direction?
The above two incorrect statements give the error:
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Just in case anyone else comes across this, I have managed to find the answer.
I was using item.HasAccess() and item.IsProtected() to try to determine whether a node is protected and, if so, whether the user has access permissions.
However, what I should have used is umbraco.library.HasAccess(item.id, item.path), where item is a valid node.
Hopefully this will help someone else in the future looking for how to do this.
Hide menu items based on permission
Hi
I'm trying to create a simple menu which will only show items that a user has access to.
For example, we have a website with a home page (public) and then two private sections A and B.
When the user is not logged in, I want to show the link to "home" only. When the user is logged in and has permission to access "section A" the menu should display "Section A".
I've seen a post about the function "WhereHasAccess()" from Umbraco 5, but can't seem to find anything about 6 or 7.
At the moment all I have is:
I thought I could have something like this:
or:
But neither option works at all.
Please can someone point me in the right direction?
The above two incorrect statements give the error:
Just in case anyone else comes across this, I have managed to find the answer.
I was using
item.HasAccess()
anditem.IsProtected()
to try to determine whether a node is protected and, if so, whether the user has access permissions.However, what I should have used is
umbraco.library.HasAccess(item.id, item.path)
, whereitem
is a valid node.Hopefully this will help someone else in the future looking for how to do this.
Could you post your whole code to see how you implemented his?
Thanks.
is working on a reply...