Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have got four different user roles, with each user having access to certain
pages. How can I setup a conditional asp.net menu based on the user access
level?
Posted
Updated 22-Feb-11 6:22am
v3
Comments
Albin Abel 22-Feb-11 5:35am    
google for URL authorization. There you can define users and their roles can be allowed

like this (assuming you are using forms authentication)

http://villagecoder.wordpress.com/2008/08/29/creating-a-role-based-aspnet-menu/
 
Share this answer
 
v2
Usually the menu links to an URL. So..

In your web config file have like this

XML
<system.web>
    <authorization>
        <deny users="?" />
    </authorization>
</system.web>
<location path="Default2.aspx">
    <system.web>
        <authorization>
            <allow users="Jack" />
            <deny users="*" />
        </authorization>
    </system.web>
</location>



so the default2.aspx will be only allowed for the users assigned. Can use comma separated users.

For more detail refer this link..

http://www.asp.net/security/tutorials/user-based-authorization-cs[^]

the Microsoft documentation

http://msdn.microsoft.com/en-us/library/wce3kxhd.aspx[^]
 
Share this answer
 
v2
Comments
Maral Azizi 22-Feb-11 8:36am    
i didn't mean that, actually i have a tree view control instead of menu and i want to define 4 type of user for example admin , customer ,... and i need that when a user log into the site the tree automatically recognize the user and just show him his related forms or links
Maral Azizi 22-Feb-11 8:40am    
i think i could make it by sitemap and xml but i need more specific help,thanks in advance
Albin Abel 26-Feb-11 0:00am    
For that you can map user type to a link list in a table and use that to show appropriate menus. Links again refer to an URL actually (an another aspx page/ webform right). So you can't escape from implementing url authorization. Because though you hide the links, a use can paste the hided link in the browser navigation bar and access that page. So it is not just hiding the page, but you have to secure it.
Maral Azizi 3-Mar-11 0:29am    
thats true , but the point is how to do it? you meant to create a login page? so i have to assign username and pass? i think i could analyse what you offer, and thank you for consideration :)
ASP.NET Menu and SiteMap Security Trimming

Please leave you comment helps or not.
 
Share this answer
 
Comments
Maral Azizi 3-Mar-11 0:33am    
it can be use too, but the point is i want to do it dynamically and i want that the website admin allocate users to pages, but thank you !

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