Reputation: 1195
How do I create a menu in a ASP.NET MVC2 Master Page, dynamically based on the current user's "role"?
Upvotes: 1
Views: 2533
Reputation: 51200
If you are using the sitemap
file to generate menus then you can probably do it in there. If not, then it depends.
Upvotes: 0
Reputation: 122684
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"); %>
<% } %>
Upvotes: 3
Reputation: 273824
I'm not sure about MVC but in 'normal' ASP.NET it is possible to select a MasterPage at runtime.
Upvotes: 1