【问题标题】:Customer ActionFilterAttribute OnActionExecuting override never called从未调用客户 ActionFilterAttribute OnActionExecuting 覆盖
【发布时间】:2014-07-13 12:11:02
【问题描述】:

我正在使用 MVC 4。

我对这个继承自 System.Web.Mvc.ActionFilterAttribute 的客户属性进行编码

public class AuthorizedAttribute : ActionFilterAttribute
{    
    public AccessLevel Threshold { get; set; }

    public AuthorizedAttribute()
    {
        Threshold = AccessLevel.Anonymous;
    }

    public AuthorizedAttribute(AccessLevel threshold)
    {
        Threshold = threshold;
    }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //some actions
        base.OnActionExecuting(filterContext);
    }
}

我在我的UserControllerManage 中使用它

public class UserController : Controller
{
    [HttpGet]
    [Authorized(AccessLevel.Administrator)]
    public ViewResult Manage()
    {
         return View();
    }
}

我在我的属性构造函数中,在覆盖的方法OnActionExecuting 和我的UserController 中放置了一个断点,当我在调试模式下通过浏览器调用操作 url 时,只有我的控制器断点被触发并且我登陆页面即使我没有经过身份验证.. 我做错了什么?

提前致谢。

【问题讨论】:

    标签: c# asp.net-mvc custom-attributes onactionexecuting


    【解决方案1】:

    您的代码应该可以工作。可能你在路由等方面有问题。

    【讨论】:

    • 不,我的路由很好,我的控制器方法中的断点正在触发,但不是我的属性中的断点..
    • 在这种情况下,我只有在项目中查看此功能时才能弄清楚。
    • 行不行还需要知道哪些其他信息?
    【解决方案2】:

    看来我没有完全使用 MVC 4,但几乎使用了 MVC 5。我只需要对我的 web.config 进行一些更新即可解决我的问题.. 我找到了我的救赎here

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 1970-01-01
      • 2016-05-03
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多