I have created a base controller that houses a UnitOfWork so that I don't have to new it up all the time . Within this controller I have also added three action filters that I want to run every request:
[ElmahLogFilter]
[LoggingActionFilter]
[RequestValidationFilter]
public class BaseController : ApiController
{
private UnitOfWork _unitOfWork;
public UnitOfWork UnitOfWork
{
get { return _unitOfWork ?? (_unitOfWork = new UnitOfWork()); }
}
}
Then I just have a controller defined like so:
[System.Web.Http.Authorize(Roles = "Host, Guest")]
public class MeetingController : BaseController
{
//Code in here
}
However none of the ActionFilters will execute when making a request. I have ensured that each ActionFilter works off of the System.Web.Http.Filters
namespace to not conflict with the MVC version. This is what one of my filters looks like:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Filters;
public class LoggingActionFilter : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
//Logging Code Here
base.OnActionExecuted(actionExecutedContext);
}
}
I have spent a while on this trying simply to execute one action filter but no dice so far. Is there anything I'm missing?
Edit:
As soon as I remove the [Authorize]
attribute, the filters work. But it is important to ensure that roles are adhered to here.