asp.netiishttphandlerihttphandleriis-8.5

ASP.Net moving custom HTTP handlers to IIS 8.5


I have been developing an application that was hosted on IIS 6 and we have just upgraded our server that uses IIS 8.5 but can't get it to work on the new server.

The application has a custom handler that's called when a file with extension .XmlDataTypes is requested.

For this to work in IIS6 I set up a mapping as:

Extension: '.XmlDataTypes' Path: 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll' Verbs: All.

In Web.config:

<httpHandlers>
  <add verb="*" path="*.XmlAmenityData" type="XmlHandler"/>
  <add verb="*" path="*.XmlDataTypes" type="XmlDataTypes"/>
</httpHandlers>

And this works fine.

In IIS8.5 I've tried adding a Managed Handler with:

Requested path: '*.XmlDataTypes' Type:, selected 'XmlDataTypes' Name: XmlDataTypes

This then added to the web.config file:

<system.webServer>
    <handlers>
        <add name="XmlAmenityData" path="*.XmlAmenityData" verb="*" type="XmlHandler" resourceType="File" preCondition="integratedMode" />
        <add name="XmlDataTypes" path="*.XmlDataTypes" verb="*" type="XmlDataTypes" resourceType="File" preCondition="integratedMode" />
    </handlers>
</system.webServer>

When I run a page that requests a URL with extension .XmlDataTypes via a jQuery function I just get an 404 not found error.

Thanks in advance for any help.

J.


Solution

  • It looks like those are files on your disk. If they are, your solution could be as simple as adding the following to your web.config under "system.webServer".

    <staticContent>
        <mimeMap fileExtension=".XmlAmenityData" mimeType="application/xml" />
        <mimeMap fileExtension=".XmlDataTypes" mimeType="application/xml" />
    </staticContent>
    

    That's it.

    However, if you are really relying on HTTP Handlers, please note that the "Type" need to be fully qualified with the assembly name at the least.

    So your type need to include the namespace as well.

    In your code, "XmlHandler" isn't fully qualified with the namespace and the assembly isn't mentioned. Ensure that it is.

    Finally, change the "resourceType" to "Unspecified" or IIS will ensure that a file truly exist before executing your handler.