I want to generate menu automatically, How can I know an action is authorized to curr开发者_StackOverflowent user(in view)?
You should look at using roles if you only need basic functionality.
http://www.asp.net/security/tutorials
http://rtur.net/blog/post/2009/06/03/Quick-and-dirty-role-management-in-ASPNET-MVC.aspx
For something more robust, but very time consuming to get started with, look at Rhino Security:
http://ayende.com/Blog/archive/2008/01/22/Rhino-Security-Overview-Part-I.aspx
You can check if the user is in a particular role from the view or the controller.
<% if (HttpContext.Current.User.IsInRole("Administrator") )
{
Html.RenderPartial("AdminMenus");
}
else
{
Html.RenderPartial("UserMenus");
}
%>
http://weblogs.asp.net/rashid/archive/2009/09/06/asp-net-mvc-and-authorization-and-monkey-patching.aspx
精彩评论