Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Comments
So, what is the problem? What have you tried?
Nelek 1-Aug-13 5:41am    
Dholakiya Ankit 1-Aug-13 6:56am    
give some code to see

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
 
Share this answer
 
Comments
krish2013 1-Aug-13 7:40am    
Hi sisir,
Your advice very good.but i don't have experience on sql server.if you have any related sp please share to me.
[no name] 1-Aug-13 7:44am    
What database you are using? I had mentioned in my solution that you can create a sp or can simply write query to retrieve the data from the table. There is no such restriction and no standard sps for this particular thing. You can write it of your own to customize your requirements.
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
XML
<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:
C#
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.
 
Share this answer
 
XML
<% If User.IsInRole("SomeAdminRole") Then%>
YOU'RE AN ADMIN! AWESOME!
<% Else%>
WHO ARE YOU?
<% End If%>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900