【发布时间】:2015-07-23 19:22:33
【问题描述】:
在我的 ASP.NET MVC 4 控制器类中,我使用 CustomAuthorize 属性装饰了一些操作,因此访问权限仅限于某些角色。
我想从操作方法中获取角色,为此我需要装饰方法的 CustomAuthorize 属性。
我该怎么做?
我正在尝试做的示例代码如下:
public class TestController : Controller
{
// Only the users in viewer and admin roles should do this
[CustomAuthorize("viewer", "admin")]
public ActionResult Index()
{
//Need CustomAuthorizeAttribute so I get the associated roles
}
}
CustomAuthorizeAttribute 是System.Web.Mvc.AuthorizeAttribute 的子类。
【问题讨论】:
标签: c# asp.net-mvc-4