主页面问题中的菜单 [英] menu in master page issue

查看:91
本文介绍了主页面问题中的菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据用户的角色动态调整asp.net主页中的菜单项





假设管理员登录时导航后的页面只有一个'添加用户'项目将被添加其他明智的相同





请分享您的答案

解决方案

HI,



您可以轻松完成。有很多过程。我想在这里讨论其中一个。



步骤1:创建所有菜单项并将它们保存在表格中,例如Menu_Table 。

步骤2:在表格中保留一个字段,用于保存管理部分的轨道。

步骤3 :创建存储过程或查询以根据用户角色弹出菜单项

(管理员或普通用户)

步骤 - 4:将用户角色从您的页面传递到存储过程,并为菜单项的相应用户弹出数据,并将值传递到母版页的菜单控件。



这不是您根据自己的要求可以采取任何方式的最终方式。我已经向您展示了一个简单的方法,您可以按照您的要求进行操作。



谢谢


这取决于您使用的逻辑。在主页面中为所有链接提供ID。并且在基于用户类型的页面加载事件中,使链接的可见性为false。您的用户类型可以是会话或cookie。



例如:

源代码

 <   div  >  
< asp:HyperLink ID = hlinkAdmin NavigateUrl = 〜/ Admin.aspx runat = 服务器 > 管理员< / asp:HyperLink >
< asp:HyperLink ID = hlinkUser NavigateUrl = 〜 /User.aspx\" runat = 服务器 > 用户< / asp:HyperLink >
< / div >



代码落后:

  public   string  uType =   Admin;  //  可以是会话或Cookie值 
protected void Page_Load( object sender,EventArgs e)
{
string errorMsg = ;
if (uType == Admin
{
hlinkUser.Visible = false ;
}
else if (uType == 用户
{
hlinkAdmin.Visible = false < /跨度>;
}
else
{
errorMsg = 未登录;
}
}





希望它可以帮到你。


< pre lang =xml> <%如果User.IsInRole( SomeAdminRole)然后%>
你是管理员!真棒!
<%否则%>
谁是你?
<%结束如果%>


how to dynamically chinge the menu items in master page in asp.net based on roles of users


suppose when admin logined the page after navigation only one 'add user'item will be added other wise it's same


Please share your answers

解决方案

HI,

You can do it easily. There are many processes. I would like to discuss one of them here.

Step-1: Create all the menu items and keep them into a table e.g Menu_Table.
step-2: Keep a field there in the table which keeps the track of the admin portion.
step-3: Create a stored procedure or a query to pop out the menu items based on the user roles
(admin or normal user)
Step-4: pass the user role from your page to the stored procedure and pop out the data for the respective user for the menu items and pass the values to the menu control at the master page.

This is not the ultimate way you can follow any way based on your requirement. I have shown you a simple way that you can follow for your requirement.

Thanks


It depends on logic that you use. In Master page give id for all links. And in page load event based on user type make visibility of the links false. Your user type can be session or cookies.

Eg:
Source code

<div>
        <asp:HyperLink ID="hlinkAdmin" NavigateUrl="~/Admin.aspx" runat="server">Admin</asp:HyperLink>
        <asp:HyperLink ID="hlinkUser" NavigateUrl="~/User.aspx" runat="server">User</asp:HyperLink>
    </div>


code behind:

public string uType="Admin"; // It can be Session or Cookie value
    protected void Page_Load(object sender, EventArgs e)
    {
        string errorMsg = "";
        if (uType == "Admin")
        {
            hlinkUser.Visible = false;
        }
        else if (uType == "User")
        {
            hlinkAdmin.Visible = false;
        }
        else
        {
            errorMsg = "Not logged in";
        }
    }



Hope it helps you.


<% If User.IsInRole("SomeAdminRole") Then%>
YOU'RE AN ADMIN! AWESOME!
<% Else%>
WHO ARE YOU?
<% End If%>


这篇关于主页面问题中的菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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