我可以隐藏/显示ASP:基于角色的菜单项? [英] Can I hide/show asp:Menu items based on role?
问题描述
我是能够隐藏在 ASP某些菜单项:菜单
控制基于角色
Am I able to hide certain menu items in an asp:Menu
control based on role?
<asp:Menu ID="mTopMenu" runat="server" Orientation="Horizontal" />
<Items>
<asp:MenuItem Text="File">
<asp:MenuItem Text="New Project" />
<asp:MenuItem Text="Release Template" NavigateUrl="~/Release/ReleaseTemplate.aspx" />
<asp:MenuItem Text="Release Schedule" NavigateUrl="~/Release/ReleaseSchedule.aspx" />
<asp:MenuItem Text="Roles" NavigateUrl="~/Admin/AdminRoles.aspx" />
</asp:MenuItem>
</Items>
</asp:Menu>
我怎样才能让这些项目只有用户可见的管理角色之一吗?
我使用asp.net角色提供。
How can I make one of these items visible to only users in the Admin role? I am using asp.net role provider.
推荐答案
您可以绑定菜单项来一个网站地图,并使用角色属性即可。您将需要启用安全修整在你的web.config做到这一点。这是最简单的方法。
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. This is the simplest way.
网站导航概述:
<一href=\"http://msdn.microsoft.com/en-us/library/e468hxky.aspx\">http://msdn.microsoft.com/en-us/library/e468hxky.aspx
安全性修剪信息:
<一href=\"http://msdn.microsoft.com/en-us/library/ms178428.aspx\">http://msdn.microsoft.com/en-us/library/ms178428.aspx
网站地图绑定信息:
<一href=\"http://www.w3schools.com/aspnet/aspnet_navigation.asp\">http://www.w3schools.com/aspnet/aspnet_navigation.asp
很好的教程/概述在这里:
<一href=\"http://weblogs.asp.net/jgalloway/archive/2008/01/26/asp-net-menu-and-sitemap-security-trimming-plus-a-trick-for-when-your-menu-and-security-don-t-match-up.aspx\">http://weblogs.asp.net/jgalloway/archive/2008/01/26/asp-net-menu-and-sitemap-security-trimming-plus-a-trick-for-when-your-menu-and-security-don-t-match-up.aspx
Good Tutorial/Overview here: http://weblogs.asp.net/jgalloway/archive/2008/01/26/asp-net-menu-and-sitemap-security-trimming-plus-a-trick-for-when-your-menu-and-security-don-t-match-up.aspx
这工作,但不太理想的另一种方法是使用 loginview 控制,可以显示基于角色的控制。这可能是最快的(但不灵活/高性能)选项。你可以在这里找到一个指南:<一href=\"http://weblogs.asp.net/sukumarraju/archive/2010/07/28/role-based-authorization-using-loginview-control.aspx\">http://weblogs.asp.net/sukumarraju/archive/2010/07/28/role-based-authorization-using-loginview-control.aspx
Another option that works, but is less ideal is to use the loginview control which can display controls based on role. This might be the quickest (but least flexible/performant) option. You can find a guide here: http://weblogs.asp.net/sukumarraju/archive/2010/07/28/role-based-authorization-using-loginview-control.aspx
这篇关于我可以隐藏/显示ASP:基于角色的菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!