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

天大地大妈咪最大 提交于 2019-12-17 04:29:25

问题


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?


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



回答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>



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




回答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>



回答5:


I fixed this removing the UrlScan ISAPI filter




回答6:


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.




回答7:


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.


回答8:


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 !




回答9:


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



来源:https://stackoverflow.com/questions/10099270/asp-net-web-api-returns-404-for-put-only-on-some-servers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!