asp.net-mvc-3 - 覆盖 OnActionExecuting 以测试请求用户是否授权调用操作?

标签 asp.net-mvc-3

我想覆盖 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/

相关文章:

c# - 重用 MVC Controller 角色授权以显示菜单项

asp.net-mvc - 是否可以从同一项目使用 WCF 服务?

c# - 在 MVC 3 Razor 中获取事件页面链接的更好方法

asp.net - Razor 与 ASPX 语法的比较

asp.net-mvc - 托管 ASP.NET MVC 3 Razor Engine 站点

javascript - 将 javascript 变量添加到 actionlink

jQuery.Ajax 与 Ajax.beginform 与不显眼的 JavaScript

asp.net-mvc-3 - 如何为 Azure 创建返回 503 的自定义维护页面?

c# - 创建我的第一个 HttpHandler - 不起作用

c# - 使用 iis express 时,没有在远程 pc 上应用 css