Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpHandler not being called

I need to write a HttpHandler that will serve up JavaScript files which are embedded resources in .DLLs in my project. A reference in a view cannot directly see such a resource, so I planned to use a HttpHandler module that would intercept any request with a path /js/[file] , find a matching embedded file and return the script.

The problem is that my HttpHandler code is never called, despite trying lots of different settings in the section of web.config. I'm obviously missing something but with no error messages I cannot see what that is. All I ever get is a 404 from the static file handler.

Q1) Am I missing something obvious?

Q2) Is there a way to get IIS to tell me why it is not calling my handler?

Summary: I am testing on IIS Express (v8) for an ASP.NET MVC 4 application.

I created a simple library that implements IHttpHandler and added a reference to this in my test MVC application, and the following lines in web.config:

  <system.webServer>
    <validation validateIntegratedModeConfiguration="true" />
    <handlers>
      <add name="ejs" path="js/*" verb="*" type="EmbeddedJsHandler.EmbeddedJsHandler, EmbeddedJsHandler" preCondition="integratedMode" />

The library is there, but it is never called. Any request with /js/test.js or whatever just results in a 404 error.

So far I've tried lots of different configurations and settings in the handler code. I've tried preCondition, resourceType="Unspecified", modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"

I've tried paths:

  js/*.js
  js/* 
  js/*.*

I've checked the integrated mode settings section (in system.webServer) is being used, and confirmed it is.

I've searched stack overflow for similar cases, and tried many of the possible solutions.. still no joy.

Heck even Jon Skeet has these sort of problems! Why isn't my IHttpHandler being called?

like image 224
Quango Avatar asked Dec 20 '12 10:12

Quango


2 Answers

Finally figured it out by accident - it was a missing routes.IgnoreRoute() in the RouteConfig.cs file - the MVC routing engine wasn't configured to ignore this path, so was passing it to the static file handler.

Doh!

like image 127
Quango Avatar answered Sep 29 '22 19:09

Quango


I cannot tell you directly why your handler isn't working, but I will give you an example of a handler we use and works for us:

<system.webServer>
    <handlers>
        <add name="JS handler" path="*.js" verb="*" type="Handlers.Minifiers.JSMinify" resourceType="Unspecified" preCondition="integratedMode" />
    </handlers>
</system.webServer>

We also have this segment, which is at least necessary for running in Cassini

<system.web>
    <httpHandlers>
        <add verb="*" path="*.js" type="Handlers.Minifiers.JSMinify" validate="false"/>
    </httpHandlers>
</system.web>

If this doesn't help, have tou tried using path="/js/*"?

like image 37
Robert Fricke Avatar answered Sep 29 '22 19:09

Robert Fricke