@Pankaj是正确的,但你可以定义找你自定义属性的考试:class MyAuthorizationAttribute : FilterAttribute, IAuthorizationFilter
和覆盖OnAuthorization的方法就可以了。然后使用此自定义属性装饰每个动作并计算OnAuthorization主体中的授权。这是一个例子:
public class MyAuthorizationAttribute : FilterAttribute, IAuthorizationFilter
{
public string _name;
public MyAuthorizationAttribute(string name)
{
this._name = curPerm.name;
}
public void OnAuthorization(AuthorizationContext filterContext)
{
// Calculate permissions...
if (!permit)
{
Exception e = new MethodAccessException("Access to partial denied!");
throw new Exception("Can't access via address bar!", e);
}
}
}
,并在行动中
[MyAuthorizationAttribute ("Add")]
public ActionResult Index()
{
ViewBag.Message = "About page";
return View();
}
希望这个有用的使用。 祝你好运。