title: How to Hide Menu Items Based on Role in ASP.Net
body: <p>I am trying to hide an Item from the Menu Items if a user is not in the Admin role.  Here is the code that i am using in the code behind in my site master but the code is not hiding the Admin page in which i am trying to hide it.  Here is the HTML markup for the master page:</p>
  
  <pre><code> &lt;asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false"
                      IncludeStyleBlock="false" Orientation="Horizontal"&gt;
                      &lt;Items&gt;
                          &lt;asp:MenuItem NavigateUrl="~/Admin/Authors.aspx" Text="Admin" /&gt;
                          &lt;asp:MenuItem NavigateUrl="~/Users/KCA_Summary.aspx" Text="KCA Summary" /&gt;
                          &lt;asp:MenuItem NavigateUrl="~/Users/Details.aspx" Text="KCA Details" /&gt;
  
                      &lt;/Items&gt;
                  &lt;/asp:Menu&gt;
  </code></pre>
  
  <p>and here is the code behind:</p>
  
  <pre><code> Protected Sub Page_Load(sender As Object, e As EventArgs)
          If Not Roles.IsUserInRole("Admin") Then
              Dim menuItems As MenuItemCollection = NavigationMenu.Items
              Dim adminItem As New MenuItem()
              For Each menuItem As MenuItem In menuItems
                  If menuItem.Text = "Admin" Then
                      adminItem = menuItem
                  End If
              Next
              menuItems.Remove(adminItem)
          End If
      End Sub
  </code></pre>