简体   繁体   中英

ASP.NET custom HttpHandler in IIS 7, 7.5

My web.config is setup as following. My handler lives in an assembly called TestProject.Custom. I am calling this handler via jQuery post, works great in VS 2010 (of course!) but when I push it out to IIS 7.5 or IIS 7, it throws 404 about not being able to find TestHandler.ashx. Not sure what I am missing.

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />

<handlers>
  <add name="TestHandler"
       verb="*" preCondition="integratedMode"
       path="TestProject.Custom.HttpHandlers.TestHandler.ashx"
       type="TestProject.Custom.HttpHandlers.TestHandler, TestProject.Custom"/>

</handlers>

Edit: I am calling this handler with jQuery and the handler is behind forms authentication (which I don't think is the problem):

jQuery(function () {
    jQuery.ajax({
        type: "POST",
        url: "TestHandler.ashx",
        data: { "test_data": "some test data" }
    });
});

I think the "path" attribute should be "TestHandler.ashx" instead of its current value. It must match the URL you use in jQuery. Otherwise, 404 is expected.

404 usually means a problem with the registration, basically it just can't find something to handle the request that came in.

Inside of the add node, try adding the following attribute at the end: resourceType="Unspecified"

That tells IIS not to look for a physical file when it sees the request for the ashx. I think that's causing the 404

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM