views:

299

answers:

2

How do I create a menu in a ASP.NET MVC2 Master Page, dynamically based on the current user's "role"?

+2  A: 

The simplest and most straightforward way would be to simply add an if statement in the view markup:

<% if (Page.User.IsInRole("Admin")) { %>
   <%= Html.ActionLink("Admin Tools Index", "Index", "Admin") %>
   <%= Html.ActionLink("Admin Dashboard", "Dashboard", "Admin") %>
<% } %>

Or, you can separate out several items pertaining to a specific role into a partial view:

<% if (Page.User.IsInRole("Admin")) { %>
   <% Html.RenderPartial("AdminMenu"); %>
<% } %>
Aaronaught
A: 

If you are using the sitemap file to generate menus then you can probably do it in there. If not, then it depends.

Joe Philllips