Search code examples
c#asp.net-mvc-3iis-7httphandlerclass-library

HttpHandler in separate assembly always returns 404


I have a created an httphandler in a separate assembly from my main application,so I can reuse the code elsewere. Below is an example of the code I am using for the handler

namespace LifespeakCustomFields{
public class CustomFieldsHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
    {
 ....

In the web.config of my primary application (using mvc3, .net 4.5) I added the following entry to the system.webserver element (I am using iis7 integrated mode)

 <handlers>
        <add name="CustomFieldsHandler" path="*.myhandler" verb="*" type="LifespeakCustomFields.CustomFieldsHandler" resourceType="Unspecified" preCondition="integratedMode" />
  </handlers>

This seems like the correct configuration, however when I make a request for this resource (/test.myhandler), it always returns a 404 error, even though it clearly exists. Not sure what the issue could be.


Solution

  • e.g. for this handler :

     <system.webServer>
        <modules>
          <remove name="FormsAuthentication" />
        </modules>
        <handlers>
          <add name="TestHandler" path="testhandler" type="ClassLibrary1.TestHandler,ClassLibrary1" verb="*" preCondition="integratedMode"/>
        </handlers>
      </system.webServer>
    

    but you also need to tell the ignore path to MVC route , in RouteConfig.cs:

    routes.IgnoreRoute("testhandler");