Let me prefix first that there are already two questions from Stack Overflow with accepted answers that async action filters are not supported:
Async action filter in MVC 4
Calling Async Methods in Action Filters in MVC 5
So, I'm looking for a 'work-around'. This is what I currently do in my WebApi application:
public class MessageLoggingHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
await LogRequestInfo(request);
var response = await base.SendAsync(request, cancellationToken);
await LogResponseInfo(response);
return response;
}
What I am trying to achieve is to log the request and log the response as a cross cutting concern. How can I do this in MVC? Is it even possible? I see two posts with a possible solution... has anyone used it? Does it work? Should I even go down this path? Are there alternatives? I'm really hesitant to adopt either approach for fear of breaking something in our application.
1) Implement a custom AsyncControllerActionInvoker
http://ayende.com/blog/163170/building-async-unit-of-work-with-mvc-4
2) Create and Async Controller Base Class, uses the "ParallelExtensionsExtras" library (whatever that is), and overrides some of the BeginExecute, EndExecute methods.
Perform Async operation asp.net mvc outside of the action