1

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

mwill
  • 424
  • 7
  • 21
  • DelegatingHandler pass thought a different way in the request pipiline. You should implement a custom HTTP handler to inspect static content – Fals Nov 25 '14 at 17:54
  • Can I configure all requests to come through the custom HTTP handler? My goal is to have 1 entry point for all request types (api/html/js/css, etc), and be able to have control over the request and especially the response code/status. – mwill Nov 25 '14 at 20:13

0 Answers0