I'm writing an Action Filter (inheriting from ActionFilterAttribute
) which uses HttpClient
to POST data to an external server in the OnResultExecuted
method. HttpClient
has the method PostAsync
which returns an awaitable Task<HttpResponseMessage>
.
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
using (var client = new HttpClient())
{
var task = client.PostAsync(GetUri(), GetContent());
var result = task.Result; // blocking
}
}
The accepted answer to Async action filter in MVC 4 says it is not possible in MVC 4.
Is this still true in MVC 5, and if so what is the best way of calling this asynchronous method without blocking the thread?