I'm trying to build a navigation for a structure with protected pages.
Why can't i do this? (HasAccess is always null) @foreach (var page in root.Children.Where("Visible && HasAccess") Same if i make an condition like if(page.HasAccess()))
But if i make an condition like if(library.HasAccess(page.Id, page.Path)) it will work.
Would like to filter with HasAccess in the foreach to keep track of first and last node.
You can find the documentation for Filtering, Ordering & Extensions in a .Where condition here, I know this documentation for DynamicNode but hope this can be a help even if you are using MVC.
HasAccess in navigation
I'm trying to build a navigation for a structure with protected pages.
Why can't i do this? (HasAccess is always null)
@foreach (var page in root.Children.Where("Visible && HasAccess")
Same if i make an condition like if(page.HasAccess()))
But if i make an condition like if(library.HasAccess(page.Id, page.Path)) it will work.
Would like to filter with HasAccess in the foreach to keep track of first and last node.
Using Umbraco 7.1.1
Hi Jonas,
How about something like this:
@foreach (var page in root.Children.Where("Visible == @0 && HasAccess == @1","False","True")
You can find the documentation for Filtering, Ordering & Extensions in a .Where condition here, I know this documentation for DynamicNode but hope this can be a help even if you are using MVC.
/Dennis
The problem is that the extension methods for HasAccess and IsProtected doesn't seem to work at all in 7.1.1.
library.HasAccess(page.Id, page.Path) returns true or false, but if I use page.HasAccess() it returns null.
/Jonas
Hi Jonas,
Have you tried something like:
@Umbraco.HasAccess(page.Id, page.Path)
In Umbraco 7 as far as I know the @Umbaco is replacing the old umbraco.library methods. Documentation can be found here under the first chapter.
http://our.umbraco.org/documentation/Reference/Mvc/views
Hope this helps,
/Dennis
I think there is much confusion regarding this topic.
It is a bit strange that something like
Where("Visible && HasAccess")
is not directly possible and that the helper is needed to check accessibility.I have posted a more elaborate question about it here.
is working on a reply...