在 asp.net 网站中动态添加项目到菜单
- 作者: 酱油男路过
- 来源: 51数据库
- 2022-10-20
问题描述
<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>
我在母版页中有这个菜单,当用户登录网站时,基于用户角色,我想从服务器端向菜单添加项目.我该怎么做.
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.
*****(添加菜单--> 组织、消息、组)用户(要添加的菜单 --> 消息、群组)
*****(menu to add --> Organisation, Message, Group) Users(menu to add --> Message, Group)
因为我有 6 个角色,所以每个角色都有不同的菜单项.这怎么办
Since I have 6 roles I have different menu item for each role. How can this be done
推荐答案
在master的Page_Load中可以查看用户是否在某些角色中,动态添加值到菜单:>
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("*****"))
{
mnu.Items.Add(new MenuItem
{
Text = "*****ister web site",
NavigateUrl = "~/*****.aspx"
});
}
}
推荐阅读
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
热点文章
团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
0
使用 MSBuild.exe 在发布模式下构建 C# 解决方案
0
当我发布 Web 应用程序时,AfterPublish 脚本不运行
0
构建时 T4 转换的产品仅在下一个构建中使用
0
ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
0
新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
0
如何将条件编译符号(DefineConstants)传递给 msbuild
0
MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
0
NuGet 包还原找不到包,没有源
0
使用 C# 6.0 功能运行 TFS 构建
0
