C# 从未调用Customer ActionFilterAttribute OnActionExecuting override
我使用的是MVC4 我对这个从System.Web.Mvc.ActionFilterAttribute继承的客户属性进行编码 我在UserController中的action Manager上使用它 我在属性构造函数、重写方法OnActionExecuting和UserController中放置了一个断点,当我在调试模式下通过浏览器调用操作url时,只有我的控制器断点被触发,即使我没有经过身份验证,我也会在页面上着陆。。 我做错了什么C# 从未调用Customer ActionFilterAttribute OnActionExecuting override,c#,asp.net-mvc,custom-attributes,onactionexecuting,C#,Asp.net Mvc,Custom Attributes,Onactionexecuting,我使用的是MVC4 我对这个从System.Web.Mvc.ActionFilterAttribute继承的客户属性进行编码 我在UserController中的action Manager上使用它 我在属性构造函数、重写方法OnActionExecuting和UserController中放置了一个断点,当我在调试模式下通过浏览器调用操作url时,只有我的控制器断点被触发,即使我没有经过身份验证,我也会在页面上着陆。。 我做错了什么 提前感谢。您的代码应该可以工作。可能您在路由等方面遇到了问题
提前感谢。您的代码应该可以工作。可能您在路由等方面遇到了问题。看来我并不完全在MVC4中,但几乎在MVC5中。我只需要在我的web.config上做一些更新来解决我的问题。。
我发现了我的救命恩典不,我的路由是好的,我的控制器方法中的断点正在触发,但属性中的断点没有触发。在这种情况下,只有在项目中查看此功能时,我才能找到它。您还需要了解哪些其他信息,以确定它是否正常?
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);
}
}
public class UserController : Controller
{
[HttpGet]
[Authorized(AccessLevel.Administrator)]
public ViewResult Manage()
{
return View();
}
}