I have a Navigation Menu that is consists of 6 Menu Items: Home, About, Financial, Human Resource and Admin. My question is, how can I disable a Menu Item if a user logs in to a different role.
For example: I've created 2 roles in the administrive website, Financial and Member. If a user logs in as a member, the person doesn't have persmission to click on the Financial Menu but still able to see it. But if a user logs in as a Financial, that person
can click on the Financial Menu
I've tried this code:
If Roles.IsUserInRole("member") Then
Dim menuItems As MenuItemCollection = NavigationMenu.Items
Dim memberItem As New MenuItem()
For Each menuItem As MenuItem In menuItems
If menuItem.Text = "Financial" Then
memberItem = menuItem
End If
Next
menuItems.Remove(memberItem)
End If
This only made specific Menu Items invisible when I user logs into their roles. If you know how to resolve this, I would be grateful.
half_fish_su...
0 Points
3 Posts
How to disable an Menu Item from the Navigation Menu
Jan 16, 2013 04:33 AM|LINK
I have a Navigation Menu that is consists of 6 Menu Items: Home, About, Financial, Human Resource and Admin. My question is, how can I disable a Menu Item if a user logs in to a different role.
For example: I've created 2 roles in the administrive website, Financial and Member. If a user logs in as a member, the person doesn't have persmission to click on the Financial Menu but still able to see it. But if a user logs in as a Financial, that person can click on the Financial Menu
I've tried this code:
If Roles.IsUserInRole("member") Then
Dim menuItems As MenuItemCollection = NavigationMenu.Items
Dim memberItem As New MenuItem()
For Each menuItem As MenuItem In menuItems
If menuItem.Text = "Financial" Then
memberItem = menuItem
End If
Next
menuItems.Remove(memberItem)
End If
This only made specific Menu Items invisible when I user logs into their roles. If you know how to resolve this, I would be grateful.
ankit.sri
Contributor
2042 Points
410 Posts
Re: How to disable an Menu Item from the Navigation Menu
Jan 16, 2013 06:11 AM|LINK
In Order to Disable a menuitem you must use right after your condition
mani2009it
Member
207 Points
82 Posts
Re: How to disable an Menu Item from the Navigation Menu
Jan 17, 2013 09:11 AM|LINK
Hi,
U need to either implement url authorization for each and every pages in web.config
Refer this : http://www.tarkia.com/blog/tag/url-authorization-in-asp-net/
or
U have to do redirect the unauthorised roles to login or Error page through code.
If Roles.IsUserInRole("member") Then
Redirect.ToErrorpage()
Pengzhen Son...
Star
8276 Points
848 Posts
Microsoft
Re: How to disable an Menu Item from the Navigation Menu
Jan 21, 2013 07:54 AM|LINK
Hi,
You can bind the menu items to a site map and use the roles attribute. You will need to enable Security Trimming in your Web.Config to do this.
For detailed information, you can refer this http://stackoverflow.com/questions/4939031/can-i-hide-show-aspmenu-items-based-on-role
Hope it can help you.
Feedback to us
Develop and promote your apps in Windows Store
half_fish_su...
0 Points
3 Posts
Re: How to disable an Menu Item from the Navigation Menu
Jan 21, 2013 12:20 PM|LINK
Thank you for your help.
half_fish_su...
0 Points
3 Posts
Re: How to disable an Menu Item from the Navigation Menu
Jan 21, 2013 12:21 PM|LINK
Thank you for your help.