Implement AuthorizeFilter as following:
public class TheAuthrizeAttribute : AuthorizationFilterAttribute
{
public async override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
var db = new MockDB();
bool pass = await db.AsyncValidate(actionContext.Request);
// validate;
if (!pass)
{
actionContext.Response = new System.Net.Http.HttpResponseMessage(HttpStatusCode.Unauthorized);
}
}
}
The db.AsyncValidate return in 500 ms. However the work flow continues without waiting for its return and the Action with this AuthorizeAttribute ultimately been executed.