Water Cooler v2
Water Cooler v2

Reputation: 33880

Why isn't my HttpHandler being called?

Okay, I am feeling like a nincompoop now asking this.

I wrote a simple blank HttpHandler and just put a break point in the ProcessRequest method, and wrote this boiler plate registration mark-up in my web.config.

<system.web>
    <httpHandlers>
      <add path = "*.jpg" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
      <add path = "*.jpeg" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
      <add path = "*.png" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
      <add path = "*.bmp" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
      <add path = "*.gif" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
      <add path = "*.ico" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
      <add path = "*.css" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false"  />
      <add path = "*.js" verb = "*" type="MyProject.BaseServices.StaticAssetHttpHandler, MyProject.BaseServices" validate = "false" />
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

Upvotes: 0

Views: 380

Answers (2)

Water Cooler v2
Water Cooler v2

Reputation: 33880

I found the problem. I had made the entries in the Web.config in the Views folder of my MVC project. Obviously, the assets I was trying to serve using my HttpHandler weren't in the Views folder.

I moved the entries to the project's root Web.config and it started working.

Upvotes: 1

Joe
Joe

Reputation: 5497

This is going to depend on which web server you are running against and what you have installed. If you right click on your project and Propeties and pick the "Web" tab you will see radio buttons for "Use Visual Studio Development Server" or "Use Local IIS Server" with an a checkbox for IIS Express (this is the default for projects on mine and my colleagues machines).

if you use the Visual Studio Development Server your configuration should work. If IIS Express is being used, the handler needs to be registered in a different spot, with a slight change in the attributes (remove validate and add name)

<system.webServer>
  <handlers>
    <add name="StaticJS" path = "*.js" verb = "*" type="AspNetWebFormsApplication.StaticAssetHttpHandler, AspNetWebFormsApplication"  />
  </handlers>
  ....
</system.webServer>

Upvotes: 0

Related Questions