如何根据角色禁用或启用导航菜单项 [英] How to disable or enable Navigation Menu Items based on roles

查看:78
本文介绍了如何根据角色禁用或启用导航菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码



 <   asp:菜单    ID   =  NavigationMenu    runat   =  server    CssClass   =  menu    EnableViewState   =  false    IncludeStyleBlock   =  false    Orientation   = 水平 >  
< 项目 >
< asp:MenuItem NavigateUrl = 〜/ Default.aspx 文本 = 主页 / >
< asp:MenuItem Navi gateUrl = 〜/ About.aspx 文字 = 关于 / >
< asp:MenuItem NavigateUrl = 〜/ StudentEnquiry.aspx 文字 = 查询表格 / >
< asp:MenuItem NavigateUrl = 〜/ Reports.aspx 文本 = 报告 / >
< / Items >
< / asp:菜单 >

< br $> b $ b



我只想在 NavigationMenu 中禁用 Reports.aspx 菜单他是普通用户,当他是管理员用户时会显示。





这是我的代码,当我从此页面重定向到 StudentEnquiry页面时,应该禁用报告页面。谁能告诉我......



<前lang =c#> 受保护 void Page_Load( object sender,EventArgs e)
{
string SAuth = Request.QueryString.Get( 0 );
if (SAuth == True
{
Label1.Text = Convert.ToString(Session [ EmpId ]);
string type = Convert.ToString(Session [ USER_TYPE]);

// Label1.Text =Authenticated;
if (type == Adm
{
// 我想我需要在这里写一些代码
Response.Redirect( StudentEnquiry.aspx?a = + Label1.Text + );
}

}
else
{
Label1.Text = 未经过身份验证;
}
}

解决方案

哦!!只需查看此页面:



详细了解您想要的内容



实施基于角色的安全性,页面访问和显示/隐藏菜单项基于角色


尝试此链接 - 基于运行时用户权限的菜单控制绑定站点地图 [ ^ ]

< br $>


动态地在ASP.NET中填充数据库中的菜单项 [ ^ ]


 <%  if (IsAdmin ==  true ){%>  
< asp:MenuItem NavigateUrl = 〜/ Default.aspx 文本 = 主页 / > ;
< asp:MenuItem NavigateUrl = 〜/ About.aspx 文字 = 关于 / >
< asp:MenuItem NavigateUrl = 〜/ StudentEnquiry。 aspx 文本 = 查询表格 / >
< asp:MenuItem NavigateUrl = 〜/ Reports.aspx 文字 = 报告 / >
<%} %>

<% else {%>

< < span class =code-leadattribute> asp:MenuItem NavigateUrl = 〜/ Reports.asp x 文字 = 报告 / >
<%} %>





IsAdmin将在Code背后保护bool


This is my code

<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                        <asp:MenuItem NavigateUrl="~/About.aspx"   Text="About"/>
                        <asp:MenuItem NavigateUrl="~/StudentEnquiry.aspx" Text="Enquiry Form"/>
                        <asp:MenuItem NavigateUrl="~/Reports.aspx" Text="Reports" />
                    </Items>
                </asp:Menu>




I just want to disable the Reports.aspx menu in NavigationMenu when he is a Normal User, it will show when he is a admin user.


This is my code, when i redirect from this page to StudentEnquiry page the Reports page should disable. could anyone tell me...

protected void Page_Load(object sender, EventArgs e)
       {
           string SAuth = Request.QueryString.Get(0);
           if (SAuth == "True")
           {
             Label1.Text = Convert.ToString(Session["EmpId"]);
             string type = Convert.ToString(Session["User_Type"]);

             //  Label1.Text = "Authenticated";
             if (type == "Adm")
             {
                 // I think i need to write some code here
                 Response.Redirect("StudentEnquiry.aspx?a=" + Label1.Text + "");
             }

           }
           else
           {
               Label1.Text = "Not Authenticated";
           }
       }

解决方案

oh!! Just check this page:

A clear cut details of what exectly you want

Implement Role based security, Page access and Show/Hide Menu items based on Role in


try this link -Binding Sitemaps with Menu Control Based on User Privilege at Runtime[^]


Dynamically populating menu items from the database in ASP.NET[^]


<% if (IsAdmin ==true ){ %>
                   <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                      <asp:MenuItem NavigateUrl="~/About.aspx"   Text="About"/>
                      <asp:MenuItem NavigateUrl="~/StudentEnquiry.aspx" Text="Enquiry Form"/>
                      <asp:MenuItem NavigateUrl="~/Reports.aspx" Text="Reports" />
          <%} %>

            <% else{ %>

                      <asp:MenuItem NavigateUrl="~/Reports.aspx" Text="Reports" />
          <%} %>



IsAdmin will be protected bool in Code behind


这篇关于如何根据角色禁用或启用导航菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆