ASP Menu With Permissions

Posted by Sharpcnet under ASP.NET on 12/17/2013 | Points: 10 | Views : 904 | Status : [Member] | Replies : 2
This is how the navigation menu looks like. Done with HTML, CSS and placed in the master page.
The idea now, is to show/hide the items and sub items based on user permissions.
For eg: a user has the permission for only sub2-2 and sub3-1...etc. So he should not see the other items in menu when he logs in.
The necessary tables and assigining roles is done. I need to apply those to the menu, somehow. Is it possible.(using ASP.Net, C#)

ITEM1    ITEM2    ITEM3  
SUB2-1 SUB3-1
SUB2-2 SUB3-2


Looking at the asp:Menu control, but seems it doesnt have the 'visible' property for li items.
Basically I am looking for something like an object/control/method,.. which I can loop through, check for each item and make it visible or hidden. Please suggest the best approach.




Responses

Posted by: vishalneeraj-24503 on: 12/17/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down

Hi you can try this
public void DisplayMenuTabs()
{
if (Session["Menu1Access"].ToString() == "True")
Menu1.Visible = true;
else
Menu1.Visible = false;
if (Session["Menu2Access"].ToString() == "True")
Menu2.Visible = true;
else
Menu2.Visible = false;
if (Session["Menu3Access"].ToString() == "True")
Menu3.Visible = true;
else
Menu3.Visible = false;
}

//Or you can find your menu as below
Menu myMenu = (Menu)Master.FindControl("menu1");
myMenu.Visible=false;

//Or you can also try

MenuItemCollection menuItems = mTopMenu.Items;
MenuItem adminItem = new MenuItem();
foreach (MenuItem menuItem in menuItems)
{
if (menuItem.Text == "Roles")
adminItem = menuItem;
}
menuItems.Remove(adminItem);

//Or do the following

MenuItem item = NavigationMenu.FindItem("Users/Manage Accounts");
item.Parent.ChildItems.Remove(item);

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/17/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Also refer:
http://msdn.microsoft.com/en-us/library/2bc0cxhc(v=vs.80).aspx
http://www.codeproject.com/Articles/366450/Permissions-and-Levels-in-ASP-Menu
http://www.codeproject.com/Tips/354696/Dynamically-populating-menu-items-from-the-databas

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response