我想知道在MVC应用程序中检查实际登录用户的权限的最佳实践是什么。我想就意见和控权人这样做。
实际上,我可以检查实际记录的用户是否在这样的角色中:
User.IsInRole("roleName");我有有权利的桌子。每个权利都包含名称和Enum权限表示。我想要完成的是IPrincipal或IIdentity的扩展方法,这样我就可以像这样检查用户的权限:
示例扩展方法:
public static class MyPrincipal
{
public static string HasRight(this IPrincipal principal, EnumRight right)
{
// THIS would be place where I would check if a user have right with specific enum.
return true/false;
}
}然后,在视图或控制器上,我可以这样使用:
if(User.HasRight(EnumRight.AddDocuments) )
{
//DO SOMETHING
}发布于 2013-12-16 04:13:26
通常,您将实现授权筛选器,并将其应用于操作方法。下面是如何实现操作过滤器的链接。
https://stackoverflow.com/questions/20599978
复制相似问题