Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I have menu and sub menu's. I want to set access permissions for these menu's based on my SQL Query forms access.

How to do this..?

see my ASPX Code
-----------------
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"  runat="server">
    <title>ASP.NET Menu + jQuery</title>
    <style type="text/css">
        li 
        { 
            border:1px solid black; 
            padding:2px 2px 2px 2px; 
            width:210px; 
            background-color:#82C0FF;
            color:black; 
            cursor:pointer;
        }
        a { color:black; font: bold 11px Verdana; }
        
        #nav table { display:inline;} 
        #nav tr { display:inline; } 
        #nav td { display:inline;} 
        #nav a {display:inline;}
    </style>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("ul.level1 li").hover(function () {
                $(this).stop().animate({ opacity: 0.7, width: "210px" }, "slow");
            }, function () {
                $(this).stop().animate({ opacity: 1, width: "170px" }, "slow");
            });
        });
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div id="menu" class="nav">
        <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" RenderingMode="List">            
            <Items>
                <asp:MenuItem NavigateUrl="~/Home.aspx"  Text="Home" Value="Home"  />
                <asp:MenuItem  Text="Master" Value="first"> 
                        <asp:MenuItem  Text="Admin" Value="Admin"></asp:MenuItem> 
                        <asp:MenuItem Text="Prod" Value="Pro"></asp:MenuItem> 
                        <asp:MenuItem  Text="MaP" Value="Mr"></asp:MenuItem> 
                        <asp:MenuItem Text="Cory" Value="Cy"></asp:MenuItem> 
                        <asp:MenuItem Text="Ponal Role Mappings" Value="ap"></asp:MenuItem> 
                </asp:MenuItem> 
                <asp:MenuItem  Text="Transaction" Value="Second"> 
                        <asp:MenuItem  Text="Dment Activities" Value="DX"></asp:MenuItem> 
                        <asp:MenuItem Text="Input" Value="SA"></asp:MenuItem> 
                        <asp:MenuItem Text="Power" Value="KP"></asp:MenuItem> 
                </asp:MenuItem> 
                 <asp:MenuItem  Text="Reports" Value="Third"> 
                        <asp:MenuItem  Text="Reports" Value="Reports"></asp:MenuItem> 
                        <asp:MenuItem  Text="Power" Value="AL"></asp:MenuItem> 
                        <asp:MenuItem Text="All" Value="XY"></asp:MenuItem> 
                </asp:MenuItem> 
                <asp:MenuItem NavigateUrl="~/arts.aspx"  Text="arts" Value="charts"  />
            </Items>
        </asp:Menu>
    </div>
    </form>
</body>
</html>


I don't want to display all the menu's at all the times.

I want to get the access rights from the table nd then menu should display.

Table Values
-------------
Admin
Employee
Customer
Reports
Others
Help


if "Admin" as "Y" in the table, then admin menu shuould display from the master menu.
Posted
Updated 11-Dec-11 21:19pm
v3

Giving access permission depend on user role is the customization of code.

1. whenever login user clicks on menu control you need check permission according to user in database then either open
the page or redirect user to Error page with message "You do not have access".
OR
1. Filter menus accordingly to user role
OR
1. user SiteMapProvider with menu control. rolebased access permission for menu control with sitemap[^]
 
Share this answer
 
Already answered a similar question, check it.

Dynamic Menu with user permission[^]
 
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