Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Membership question:  Menus based on role

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
VB Programmer - 09 Oct 2007 02:55 GMT
I have 3 roles in my ASP.NET webapp:  Admin, Manager & User (higheset to
lowest)

When the user logs in I want 1 or more custom menues to appear:
Admin: Show menu1, menu2, menu3
Manager:  Show menu2, menu3
User:  Show menu3

What is the best way to do this?  In the past I've used 3 panels which I
turned invisible based on the role in the Form_Load event.  But, I know
there must be a better way to show the correct menus based on the role
assigned to the user.

I experimented a bit with the LoginView control, but couldn't get it to show
up right, for example...
   <asp:RoleGroup Roles="Admin">
       <ContentTemplate>
           This only shows up for the ADMIN
       </ContentTemplate>
   </asp:RoleGroup>
   <asp:RoleGroup Roles="Admin,Manager">
       <ContentTemplate>
           This only shows up for the MGR
       </ContentTemplate>
   </asp:RoleGroup>
   <asp:RoleGroup Roles="Admin,Manager,User">
       <ContentTemplate>
           This only shows up for the USER
       </ContentTemplate>
   </asp:RoleGroup>

When logged in as an ADMIN I would expect all 3 to show up but only the
ADMIN one shows up.

Any ideas?

Thanks in advance!
Kevin Spencer - 09 Oct 2007 11:07 GMT
If you're using a Membership Provider and Role Provider, you can use a
web.sitemap in conjunction with your web application to restrict access to
pages. In addition, menu controls that are bound to the XmlSiteMapProvider
will automatically hide menu items to pages that are not available to the
logged-in user, as well as restrict direct access to those pages. The
web.sitemap can include role attributes, as in the following example:

 <siteMapNode url="~/employment/Default.aspx" title="Employment"
  description="Join the professional team of Example." roles="*">
  <siteMapNode url="~/Employment/opportunities.aspx" title="Opportunities"
   description="Example &#38; Associates, Inc. Opportunities for
Employment"  roles="*"/>
  <siteMapNode url="~/Employment/benefits.aspx" title="Benefits"
   description="Example &#38; Associates, Inc. Benefits"  roles="*"/>
  <siteMapNode url="~/Employment/leaving_military.aspx" title="Leaving the
Military?"
   description="Example &#38; Associates, Inc. Opportunites for Those
Leaving the Military"  roles="*"/>
 </siteMapNode>
 <siteMapNode url="~/partners/Default.aspx" title="Contract Vehicles"
  description="Some of the fine organizations that have partnered with
Example &#38; Associates, Inc.." roles="*">
 </siteMapNode>

Signature

HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

>I have 3 roles in my ASP.NET webapp:  Admin, Manager & User (higheset to
>lowest)
[quoted text clipped - 33 lines]
>
> Thanks in advance!
VB Programmer - 09 Oct 2007 14:32 GMT
Thanks Kevin!

> If you're using a Membership Provider and Role Provider, you can use a
> web.sitemap in conjunction with your web application to restrict access to
[quoted text clipped - 57 lines]
>>
>> Thanks in advance!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.