Problem mapping HttpHandler --> HTTP Error 404 Not Found

前端 未结 7 1759
误落风尘
误落风尘 2020-12-29 02:14

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

This is the relevant config bit:


  

        
相关标签:
7条回答
  • 2020-12-29 02:47

    Hopefully my solution will help others. On a server move from IIS6 to 7.5, both .Net 4.0 Integrated, I had a Captcha control that quit working. It turns out that removing this attribute preCondition="integratedMode,runtimeVersionv2.0" from the <add> node in <system.webserver><handlers> resolved the issue.

    0 讨论(0)
  • 2020-12-29 02:50

    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.

    0 讨论(0)
  • 2020-12-29 02:53

    It is also possible to experience this error if you have set up the handler for 32 bit, but you are running in 64 bit (or vice versa). It's easy to set up both and have all the bases covered.

    Note "preCondition", and "scriptProcessor" differences.

    <handlers>
        <add name="MyHandler_32bit" verb="*" path="*MyHandler.hndlr" preCondition="bitness32" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" />
        <add name="MyHandler_64bit" verb="*" path="*MyHandler.hndlr" preCondition="bitness64" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
    
    0 讨论(0)
  • 2020-12-29 02:56

    Just as a guide for those stuck with this problem I found the crucial attribute to be..

    resourceType="Unspecified"
    

    I originally followed a Microsoft example to set this up and they had it as

    resourceType="File"
    

    which just kept giving me 404 errors. My HTTPHandler is returning graphics.

    Hope this helps :)

    0 讨论(0)
  • 2020-12-29 03:01

    None of the previous answers worked for me.
    I'm using IIS 8.5, .Net v4.0, Integrated, and was still getting a 404 with the following handler config:

    <system.webServer>
        <handlers>
           <add name="testEmail" path="*.em" verb="*" type="MyApp.testRazorEmailHandler, MyApp" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
    </system.webServer>
    


    I enabled tracing and found the following :

    116. -HANDLER_CHANGED 
    
        OldHandlerName              testEmail 
        NewHandlerName              System.Web.Mvc.MvcHandler 
        NewHandlerModules           ManagedPipelineHandler 
        NewHandlerScriptProcessor
        NewHandlerType              System.Web.Mvc.MvcHandler, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 
    


    As you can see it looks like it had correctly picked up the request using my custom HttpHandler testEmail but MVC had stolen it.
    I opened my route definitions in RouteConfig.cs and found that adding:

       routes.IgnoreRoute("{resource}.em");
    

    I got it to ignore requests meant for my Handler.
    Hope this helps someone - I was tearing my hair out!

    0 讨论(0)
  • 2020-12-29 03:08

    i am using IIS7, the solution is:

    in section

    <system.web>
        <httpHandlers>
            <add verb="*" path="*.ashx" type="CVOS.MyDocumentHandler"/>
        </httpHandlers>
    <system.web>
    

    and section

    <system.webServer>
        <handlers>
           <add name="pdfHandler" verb="*" path="*.ashx"   type="CVOS.MyDocumentHandler" /> 
        </handlers>
    </system.webServer>
    
    0 讨论(0)
提交回复
热议问题