views:

608

answers:

2

I am having problems trying to map an HttpHandler in the web.config.

This is the relevant config bit:

<httpHandlers>
  <add verb="*" path="*.hndlr" type="MyAssembly.MyHandler, MyAssembly" validate="false" />
</httpHandlers>

When I navigate to http://localhost/myApp/whatever.hndlr I am getting a server error 404 (not found).

It's the 1st time I am hooking up an HttpHandler so I might be missing something - any help appreciated!

UPDATE:

I managed to get it working using both answers so far - who's able to exaplin why it works gets the answer marked!

This is my config (won't work if Don't have both - I am running IIS7 in classic mode)

System.web:

<httpHandlers>
    <add verb="*" path="*MyHandler.hndlr" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false"/>
</httpHandlers>

System.webserver:

<handlers>
    <add name="MyHandler" verb="*" path="*MyHandler.hndlr" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
+2  A: 

Are you using IIS7, if so is the application pool running in classic or pipelined mode? If it is IIS7 in pipelined mode then the handler reference needs to go into the following section

<system.webServer>
    <handlers>
    </handlers>
<system.webServer>

rather than in the following section.

<system.web>
    <httpHandlers>
    </httpHandlers>
</system.web>
Ben Robinson
+1 i like this. deleted my answer until OP comes back with a yay or nay.
Sky Sanders
tried (had to add name="MyHandler" to the attributes) - looks promising but getting a different error now --> HTTP Error 500.21 - Internal Server Error Handler "MyHandler" has a bad module "ManagedPipelineHandler" in its module list
JohnIdol
to answer your other question I am running in classic mode (not pipelined) - which explains why I am getting the error described in the comment above :)
JohnIdol
@JohnIdol - Did you manage to get your http handler working?
Wallace Breza
Yes the solution was a bit of a mixture between the two answers - I am about to post the solution and who's able to better explain what the heck is going on gets the points! :)
JohnIdol
+1  A: 

What is the extension of your handler? If you are using a custom extension like .hndlr you may also need to add a ScriptMap in IIS and point it to the ASP.NET runtime so that IIS can forward the request to the correct processor.


  1. In IIS7 go to your website
  2. Under the IIS group go to Handler Mappings
  3. Under Actions click Add Script Map
  4. Set Request Path to *.hndlr
  5. Set Path to the ASP.NET runtime (%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll) or whatever version you are running.

Then in your web.config you will need to register the handler in the appropriate section as described in the other answer.

Wallace Breza