ASP.NET Web API returns 404 for PUT only on some servers

31,851

Solution 1

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>
    ...

Solution 2

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>

Solution 3

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 :)

Solution 4

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>

Solution 5

I fixed this removing the UrlScan ISAPI filter

Share:
31,851
Greg Bacchus
Author by

Greg Bacchus

Updated on January 17, 2020

Comments

  • Greg Bacchus
    Greg Bacchus over 4 years

    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?