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
2010-04-18 22:07:09
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
2010-04-18 22:27:15