【发布时间】:2011-07-29 19:03:20
【问题描述】:
我有一个控制器,它应该只在加载特定参数时请求授权。比如参数ID为8的时候。
我想出了使用这样的自定义验证属性:
public class MyAuthorizeAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (/* Action's inputparameter ID = 8 */)
{
return base.AuthorizeCore(httpContext);
}
return true;
}
}
我的动作看起来是这样的(不是很有趣)
[MyAuthorize]
public ActionResult Protected(int id)
{
/* custom logic for setting the viewmodel from the id parameter */
return View(viewmodel);
}
问题是如您所见,我不知道如何在授权属性中检查该 ID 参数。 你能帮我解决一下吗?
【问题讨论】:
标签: asp.net-mvc-3 authorization custom-attributes