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

9

33

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?

Milksop answered 11/4, 2012 at 3:6 Comment(1)
Did my answer help? Did you try it?Algie
A
28

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>
    ...
Algie answered 11/4, 2012 at 7:21 Comment(1)
Sometimes WebDAV is the culprit for PUT problems however the fact that this problem is specifically WebApi (which uses extentionless url handler) I would suggest that people try Kevin Ortman's answer first.Palpebrate
L
52

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>
Lingual answered 19/4, 2012 at 4:15 Comment(7)
This solved #11258249 for me (the question turned out to be a duplicate of this question).Verlie
Worked for me with only the <handlers> part. Note that runAllManagedModulesForAllRequests should be avoided, and here it does not seem needed.Frantic
This --> <modules runAllManagedModulesForAllRequests="true" /> is what is making everything work. It tells IIS to ignore the "preConditions" set in the handlers.Dipnoan
Our DevOps team would cringe at verb="*" but this is effectively configuring IIS to accept all verbs. You could also manually change the configuration for these handlers in the IIS HttpHandlers configuration screen.Palpebrate
Adding <modules runAllManagedModulesForAllRequests="true" /> was what solved the problem for me.Harlem
The <handlers>...</handlers> part was what did it for meFunest
<handlers> for me too. I'm wondering if I encountered this because my project started out as an MVC UI project that I then added a Web API too afterwards?Endorsed
A
28

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>
    ...
Algie answered 11/4, 2012 at 7:21 Comment(1)
Sometimes WebDAV is the culprit for PUT problems however the fact that this problem is specifically WebApi (which uses extentionless url handler) I would suggest that people try Kevin Ortman's answer first.Palpebrate
R
13

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

Refulgent answered 15/11, 2016 at 20:57 Comment(2)
Extremely helpful! This should be checked first.H
This worked for me. But curious to know what was the root cause. I had just updated some ASP.Net Web API packages which automatically changed some settings in web.config and the issue started. There was absolutely nothing changed on IIS.Llama
P
5

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>
Pinfold answered 27/11, 2012 at 5:34 Comment(0)
P
4

I fixed this removing the UrlScan ISAPI filter

Parochialism answered 19/5, 2015 at 15:56 Comment(0)
A
4

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.

Anaerobe answered 27/7, 2015 at 20:46 Comment(0)
Q
1

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>
    
Which Worked very well for me.
Queeniequeenly answered 15/4, 2014 at 19:48 Comment(0)
A
1

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 !

Ardellardella answered 31/8, 2018 at 9:24 Comment(0)
P
0

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

Pianissimo answered 11/7, 2014 at 1:52 Comment(1)
in the event you were using OWIN middleware and hosting on IIS then the problem was likely because OWIN only supports integrated modeSaville

© 2022 - 2024 — McMap. All rights reserved.