33
votes

I have written a site that uses ASP.NET MVC Web API and everything is working nicely until I put it on the staging server. The site works fine on my local machine and on the dev web server. Both dev and staging servers are Windows Server 2008 R2.

The problem is this: basically the site works, but there are some API calls that use the HTTP PUT method. These fail on staging returning a 404, but work fine elsewhere.

The first problem that I came across and fixed was in Request Filtering. But still getting the 404.

I have turned on tracing in IIS and get the following problem.

168. -MODULE_SET_RESPONSE_ERROR_STATUS 
ModuleName IIS Web Core 
Notification 16 
HttpStatus 404 
HttpReason Not Found 
HttpSubStatus 0 
ErrorCode 2147942402 
ConfigExceptionInfo  
Notification MAP_REQUEST_HANDLER 
ErrorCode The system cannot find the file specified. (0x80070002) 

The configs are the same on dev and staging, matter of fact the whole site is a direct copy.

Why would the GETs and POSTs work, but not the PUTs?

9
Did my answer help? Did you try it?Aliostad
Yes it did work, thank you.Greg Bacchus

9 Answers

49
votes

For those of you who do not have WebDAV enabled but are still running into this issue using MVC 4's Web API's...

Steve Michelotti documented a solution that worked for me here.

At the end of the day, I enabled all verbs (verb="*") to the ExtensionlessUrlHandler-Integrated-4.0 handler in my web config.

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
</system.webServer>
27
votes

Those IIS servers have web-dav module installed on them and i bet it is not needed and it was installed because the person installing ticked all boxes.

Just remove web-dav from iis.

Alternatively use web.config to remove web dav module:

<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    ...
13
votes

It seems there are a number of reasons that this occurs. None of the above quite worked for me. I already had the ExtensionlessUrlHandler settings in web.config with all the required HTTP verbs. In the end I had to make the following changes in IIS:

  • In IIS select your website and double-click Handler Mappings
  • Find ExtensionlessUrlHandler-ISAPI-4.0_32bit and double-click
  • In the dialog that appears, click Request Restrictions
  • On the Verbs tab add the missing HTTP verbs separated by commas (in my case it was PUT and DELETE
  • Click Ok where required and answer Yes in the Edit Script Map dialog that pops up.
  • Repeat for ExtensionlessUrlHandler-ISAPI-4.0_64bit

Hope this helps somebody :)

5
votes

My hosting provider could NOT uninstall WebDAV as this would affect everyone.

This, runAllManagedModulesForAllRequests="true" , worked but was not recommended.

Many fixes included removing the module for WebDAVModule but that still didn't work. I removed the handler also, and finally I could use all verbs POST GET PUT DELETE.

Remove WebDAVModule and WebDAV in modules and handlers.

<modules>
    <remove name="WebDAVModule" />
</modules>
<handlers>
    <remove name="WebDAV" />
</handlers>
4
votes

I fixed this removing the UrlScan ISAPI filter

4
votes

In my case, none of these solutions applied.

I fixed it by changing my app pool to Integrated instead of Classic.

The handler:

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

is not going to work with a Classic app pool, since its preCondition is integratedMode.

1
votes

Rick Strahl from West-Wind recommended the following:

    < handlers>
    < remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
    < add name="ExtensionlessUrlHandler-Integrated-4.0"
    path="*."
    verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS"
    type="System.Web.Handlers.TransferRequestHandler"
    preCondition="integratedMode,runtimeVersionv4.0"
    />
    < /handlers>
    
1
votes

Hi For me none of the solutions worked. I finally got it working doing this :

1) In IIS select you application.
2) Go to Request Filtering
3) Then select the HTTP Verbs tab
4) I found the PUT and other verbs to have allowed to false but wasn't able to just edit so I removed the verb then either in the pane on the right select allow verb or right click on the list and select it. Enter the verb you're having troubles with and voilà !

Hope this will help someone !

0
votes

I resolved this by changing my application pool for the website to Integrated mode when it was previously on Classic mode.