【发布时间】:2011-01-05 11:41:46
【问题描述】:
我有一个用 AuthorizeAttribute 装饰的控制器。控制器包含几个都需要身份验证的操作,除了一个需要 CustomAuthorizeAttribute 提供的自定义身份验证的操作。
我的问题是,一旦我在控制器级别添加了 [Authorize],我可以在一个操作上使用 [CustomAuthorize] 覆盖它(或删除它)吗?还是我必须从控制器级别删除 [Authorize] 并将其单独添加到每个其他操作?
我纯粹是为了方便,因为我很懒,不想用 AuthorizeAttribute 装饰每个动作。
[Authorize]
public class MyController : Controller {
//requires authentication
public ViewResult Admin() {
return View();
}
//... a lot more actions requiring authentication
//requires custom authentication
[CustomAuthorize] //never invoked as already failed at controller level
public ViewResult Home() {
return View();
}
}
【问题讨论】:
-
懒惰 = 高效
标签: asp.net-mvc