Customer ActionFilterAttribute OnActionExecuting override永远不会被调用

时间:2014-07-13 12:11:03

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

我正在使用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);
    }
}

我正在Manage

中的UserController行动中使用它
public class UserController : Controller
{
    [HttpGet]
    [Authorized(AccessLevel.Administrator)]
    public ViewResult Manage()
    {
         return View();
    }
}

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

提前感谢。

2 个答案:

答案 0 :(得分:0)

您的代码应该有效。可能你在路由等方面遇到了麻烦。

答案 1 :(得分:0)

看起来我不是完全在MVC 4中,而是在MVC 5中。我只需要在我的web.config上做一点更新来解决我的问题。 我找到了我的救恩here