我想覆盖 Controller 的 OnActionExecuting 方法,我将检查操作和 Controller 用户是否有权利。
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”
你能给个主意吗?谢谢。
最佳答案
以后有帮助
public class BrowseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
filterContext.Result = new RedirectToAction("NoAccessRight");
}
public ActionResult NoAccessRight()
{
return View("_NoAccessRight");
}
}
关于asp.net-mvc-3 - 覆盖 OnActionExecuting 以测试请求用户是否授权调用操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6565617/