覆盖OnActionExecuting用于测试请求是否允许用户进行呼叫操作?

时间:2011-07-03 21:16:07

标签: asp.net-mvc-3

我想覆盖控制器OnActionExecuting方法,我会检查操作和控制器用户是否正确。

    public class BrowseController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //TODO: ask service user has right this action.
            //string actName = filterContext.ActionDescriptor.ActionName;
            //string cntName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName
            //foo(actName, cntName, userInfo) if return false go NoAccess page!
            //filterContext.Result = new RedirectResult("_NoAccessRight");

            base.OnActionExecuting(filterContext);
     }
   }

我想在用户权限验证后

filterContext.Result = new RedirectResult("_NoAccessRight");

但我无法获得页面“_NoAccessRight”以及〜/ shared / _NoAccessRight“

你能说出来吗?感谢。

1 个答案:

答案 0 :(得分:4)

为了以后的帮助

public class BrowseController : Controller
{
    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        filterContext.Result = new RedirectToAction("NoAccessRight");
   }

   public ActionResult NoAccessRight() 
   {
       return View("_NoAccessRight");
   }
}