問題描述
<asp:Menu ID="mnu" runat="server" PathSeparator="," CssClass="menu" DynamicMenuItemStyle-CssClass="menu">
<Items>
<asp:MenuItem Text="home" NavigateUrl="~/Default.aspx" />
<asp:MenuItem Text="Aboutus" NavigateUrl="#"/>
<asp:MenuItem Text="Support" NavigateUrl="#" />
</Items>
</asp:Menu>
我在母版頁中有這個(gè)菜單,當(dāng)用戶登錄網(wǎng)站時(shí),基于用戶角色,我想從服務(wù)器端向菜單添加項(xiàng)目.我該怎么做.
I have this menu in master page, When the user logs into the website, based on the user role I want to add items to the menu from the server side. How can I do that.
Admin(添加菜單--> 組織、消息、組)用戶(要添加的菜單 --> 消息、群組)
Admin(menu to add --> Organisation, Message, Group) Users(menu to add --> Message, Group)
因?yàn)槲矣?6 個(gè)角色,所以每個(gè)角色都有不同的菜單項(xiàng).這怎么辦
Since I have 6 roles I have different menu item for each role. How can this be done
推薦答案
在master的Page_Load
中可以查看用戶是否在某些角色中,動(dòng)態(tài)添加值到菜單:>
In the Page_Load
of the master you could check whether the user is in some roles and dynamically add values to the menu:
protected void Page_Load(object sender, EventArgs e)
{
if (User.IsInRole("admin"))
{
mnu.Items.Add(new MenuItem
{
Text = "Administer web site",
NavigateUrl = "~/admin.aspx"
});
}
}
這篇關(guān)于在 asp.net 網(wǎng)站中動(dòng)態(tài)添加項(xiàng)目到菜單的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!