1
votes

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.

2

2 Answers

1
votes

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.

1
votes

None of the answers I've found here or on similar questions on stackoverflow 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!