Custom authorization inside WebApi

433 Views Asked by At

I would like to know how can I change the order or do something to control the execution order of methods.

I have this class prototype:

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public abstract class ApiDbAuthAttribute : System.Web.Http.Filters.ActionFilterAttribute, IAuthorizationFilter {
     public override void OnActionExecuting(HttpActionContext actionContext) {
         // this I want to go off first
     }

     public void OnAuthorization(AuthorizationContext filterContext) {
        // this I want to go off after the first
     }

     public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) {
        // this at the end
     }
}

What actually is going on:

 1. OnAuthorization
 2. OnActionExecuting
 3. OnActionExecuted 

I know that, this is the correct order and I know it's should be that way, But I'm triggering UnitOfWork OnActionExecuting, the reason why I'm using DB when I'm using this filter.
PS: I'm using

using IAuthorizationFilter = System.Web.Mvc.IAuthorizationFilter;

I know there a difference between System.Web.Http.Filters.IAuthorizationFilter, But I haven't found the to implement this and I don't know if I needed to do it at all.

How can I change the order or how can I solve that ?

0

There are 0 best solutions below