I would like to execute an API call via attribute before a route execution. I created a customer action filter and use the OnExecuting() override function.
Within the function I awaite an async API call to another server. However, while debugging I notice the Route executes before that async call is complete. How can I accomplish this.
[CustomAttribute("Stuff")]
[Route("MyRoute")]
public async Task<IHttpActionResult> MyRoute()
{
await anotherAsyncFunction();
return Ok();
}
And the definition of the Custom Action Filter.
public class CustomAttribute : ActionFilterAttribute
{
private string att;
public CustomAttribute(string a)
{
att = a;
}
public async override void OnActionExecuting(HttpActionContext actionContext)
{
await MyFirstAsyncFunction();
}
}
Unfortunately this doesn't finish before the route code executes.