我有一个从数据库填充的数据UI的下拉列表。我有2个角色用户和管理员。如果用户没有访问数据的权限,我们是否可以根据模型属性显示错误,如下所示。
[permission]
public details {get; set; }我正在尝试向用户显示验证消息,如“您没有访问下拉列表的权限”。如果我可以使用authorize并显示错误消息,你能告诉我一些想法吗?
发布于 2014-06-12 17:31:02
http://typecastexception.com/post/2013/11/11/Extending-Identity-Accounts-and-Implementing-Role-Based-Authentication-in-ASPNET-MVC-5.aspx
还有这里:
Access Control in ASP.NET MVC using [Flags] based Enum to int permissions management in SQL
@if(User.IsInRole(“管理员”)){ @Html.DropdownListFor( expression: M => m.SelectedItemId,selectList: Model.YourCollection,optionLabel:“一些文本”) }
发布于 2014-06-13 06:37:50
您也可以使用这样的AuthorizeAttribute。
public class FVAuthorizeAttribute : AuthorizeAttribute
{
private readonly bool _authorize;
private readonly string[] _roles;
public FVAuthorizeAttribute()
{
_authorize = true;
}
}然后使用像这样的东西
FVAuthorize(角色=“管理员,NameOfMethodHereThatCreatesDropdown")
公共详情{get;set;}
https://stackoverflow.com/questions/23379689
复制相似问题