title: Umbraco 7 hide navigation nodes user has no access to
body: <p>I've seen some examples in previous versions of Umbraco (namely 5) where this seemed to be relatively straightforward. See <a href="https://stackoverflow.com/questions/10064231/umbraco-5-ask-if-user-has-permission-to-node">this stackoverflow question</a> for example.</p>
  
  <p>The theory is that I can use a property <code>HasAccess</code> or <code>IsProtected</code> on a node, or the method <code>WhereHasAccess</code> when selecting which nodes to use.</p>
  
  <p>The code I have so far is:</p>
  
  <pre><code>var nodes = @CurrentPage.AncestorsOrSelf(1).First().Children;
  </code></pre>
  
  <p>This gets me the list of pages, no problem. However, I am struggling to filter the list of pages so that a logged in user only sees what they have access to and a public visitor sees no protected pages.</p>
  
  <p>The V5 code suggests this is possible:</p>
  
  <p><code>var nodes = @CurrentPage.AncestorsOrSelf(1).First().Children.WhereCanAccess();</code></p>
  
  <p>But this results in the error:</p>
  
  <p><code>'Umbraco.Web.Models.DynamicPublishedContentList' does not contain a definition for 'WhereCanAccess'</code></p>
  
  <p>The latest published version of the <a href="http://our.umbraco.org/FileDownload?id=8865" rel="nofollow noreferrer">Razor cheatsheet for Umbraco</a> indicates that <code>HasAccess()</code> and <code>IsProtected()</code> are two methods that are both available, but when using either of these I get null values, e.g.:</p>
  
  <pre><code>@foreach(var node in nodes.WhereCanAccess()) {
      &lt;li&gt;@node.Name / @node.IsProtected / @node.IsProtected() / @node.HasAccess() / @node.HasAccess &lt;/li&gt;
  }
  </code></pre>
  
  <p>Returns null for all the test values (e.g. <code>@node.IsProtected</code>).</p>
  
  <p>It seems that what I am trying to achieve is simple, but I am approaching it the wrong way. Someone please point out the error of my ways!</p>