Thursday, January 23, 2014

Customizing MVC Action Filters

  • Authorization - System.Web.MVC.IAuthorizationFilter
  • Action- System.Web.MVC.IActionFilter
    • OnActionExecuting 
    • OnActionExecuted
  • Result - System.Web.MVC.IResultFilter
    • OnResultExecuting
    • OnResultExecuted
  • Exception - System.Web.MVC.IExceptionFilter
    • OnException

While customizing the filter, we can define attribute usage
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]

Once you create the custom filter, you need to register for it, You do this by adding them in the App_Start/FilterConfig.cs, in the RegisterGlobalFilters method:

filters.Add(new MyCustomAttribute());

No comments:

Post a Comment