Membership question: Menus based on role

V

VB Programmer

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!
 
K

Kevin Spencer

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 & Associates, Inc. Opportunities for
Employment" roles="*"/>
<siteMapNode url="~/Employment/benefits.aspx" title="Benefits"
description="Example & Associates, Inc. Benefits" roles="*"/>
<siteMapNode url="~/Employment/leaving_military.aspx" title="Leaving the
Military?"
description="Example & 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 & Associates, Inc.." roles="*">
</siteMapNode>


--
HTH,

Kevin Spencer
Microsoft MVP

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

VB Programmer

Thanks Kevin!

Kevin Spencer said:
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 & Associates, Inc. Opportunities for
Employment" roles="*"/>
<siteMapNode url="~/Employment/benefits.aspx" title="Benefits"
description="Example & Associates, Inc. Benefits" roles="*"/>
<siteMapNode url="~/Employment/leaving_military.aspx" title="Leaving the
Military?"
description="Example & 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 & Associates, Inc.." roles="*">
</siteMapNode>


--
HTH,

Kevin Spencer
Microsoft MVP

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top