Click here to Skip to main content
14,920,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo,

I want to change the navigation menu of my master page, depending on some variables, i.e. if the user has admin rights.
One menu item called "admin" (including sub-items) should only be displayed, if the user has admin rights (saved as AppSetting).
How can I do that? I'm using asp.net with vb
Posted

Hi,

Try this code

XML
<% if (System.Configuration.ConfigurationManager.AppSettings["appname"].ToString() == "Admin") {
   %>
<asp:Menu ID="Menu1" runat="server">
 <Items >
  <asp:MenuItem Text ="Admin" NavigateUrl ="admin.aspx"></asp:MenuItem>
 </Items>
</asp:Menu>
   <%
   } else {
   %>
     <asp:Menu ID="Menu2" runat="server">
 <Items >
  <asp:MenuItem Text ="User" NavigateUrl ="user.aspx"></asp:MenuItem>
 </Items>
</asp:Menu>
   <%
   } %>



I hope you understood What i did

All the Best
   
... and another way to achieve a similar result :-)

ASP.NET
<asp:Menu
    ID="Menu1" 
    runat="server" 
>
    <items>
        <asp:MenuItem text="Home" navigateurl="~/" selectable="true" enabled="true" />
        <asp:MenuItem text="Admin" selectable="false" enabled="false">
            <asp:MenuItem text="AdminLink" selectable="true" navigateurl="~/admin/Link.aspx" />
        </asp:MenuItem>
    </items>
</asp:Menu>


... and in your code behind, enable the Admin menu for the correct user type.

C#
MenuItem miAdmin = Menu1.FindItem("Admin");
if (oUser.UserType.ToLower().CompareTo("administrator") == 0)
{
       miAdmin.Enabled = true;
}
   
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900