I have an MVC/Web API, NET4.5 application. I created my own custom handler like so:
public class MyMessageHandler : DelegatingHandler
{
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var requestDate = request.Headers.Date;
// do something with the date ...
var response = await base.SendAsync(request, cancellationToken);
var responseDate = response.Headers.Date;
// do something with the date ...
return response;
}
}
That works great for API requests (http://server.com/api/resource).
I have also configured web.config to run all requests through managed modules:
<modules runAllManagedModulesForAllRequests="true">
If a request for an "html" or "js" file comes in, it is not going through my MyMessageHandler. I would like it to.
Also, not sure if this helps or not, but requests for static files DO go through Application_BeginRequest and Application_EndRequest in global.asax. I could put my code there but I would prefer it to be in MyMessageHandler.
thanks