Web API Put Request generates an Http 405 Method Not Allowed error

Web API Put Request generates an Http 405 Method Not Allowed error

So, I checked Windows Features to make sure I didn't have this thing called WebDAV installed, and it said I didn't. Anyways, I went ahead and placed the following in my web.config (both front end and WebAPI, just to be sure), and it works now. I placed this inside <system.webServer>.

<modules runAllManagedModulesForAllRequests="true">
    <remove name="WebDAVModule"/> <!-- add this -->
</modules>

Additionally, it is often required to add the following to web.config in the handlers. Thanks to Babak

<handlers>
    <remove name="WebDAV" />
    ...
</handlers>

405 Method Not Allowed PUT

Did you decorate your action with HttpPut from the correct namespace? Should look something like this :

[HttpPut]
public ActionResult ActionName() 
{
  //Your code
}

Edit: Apparently iis express has delete & put disabled by default. If this only happens in iis express you might find this answer usefull. Basicly you have to edit this file :

%userprofile%\documents\iisexpress\config\applicationhost.config 

On this line:

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

And add the verb PUT

Edit nr 2:
Following This anwser : open up your iis manager and select you website.
Click handler mapping link on the right.
Find the ExtensionlessUrlHandler-Integrated-4.0 entry and double click it.
In Request Restrictions tab verbs you can then add put to enable put support.

 

HttpPut in Asp.net Mvc 5?

Another possibility is to update the ExtensionlessUrlHandler-Integrated-4.0.

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

This solution can be found on: Attribute routing with http PUT method constraint

 

上面这个还不起作用的话,可能是因为IIS 7.5导致的问题

“405 method not allowed” in IIS7.5 for “PUT” method

回答1

Often this error is caused by the WebDAV module that try to handle this kind of requests.

An easy solution is to remove it from modules and from handlers of the system.webServer section just inside your web.config file. Here a configuration example:

<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
    <handlers>
        <remove name="WebDAV" />
    </handlers>
</system.webServer>

 

回答2,如果你确实需要使用WebDAV的话

I had this problem with WebDAV when hosting a MVC4 WebApi Project. I got around it by adding this line to the web.config:

<handlers>
  <remove name="WebDAV" />
  <add name="WebDAV" path="*" verb="*" modules="WebDAVModule"
      resourceType="Unspecified" requireAccess="None" />
</handlers>

As explained here: http://evolutionarydeveloper.blogspot.co.uk/2012/07/method-not-allowed-405-on-iis7-website.html

 

回答3

通过追踪错误提示,得到具体信息

I enabled the Failed Request Tracing, and got the following info:

 <EventData>
  <Data Name="ContextId">{00000000-0000-0000-0F00-0080000000FA}</Data>
  <Data Name="ModuleName">WebDAVModule</Data>
  <Data Name="Notification">16</Data>
  <Data Name="HttpStatus">405</Data>
  <Data Name="HttpReason">Method Not Allowed</Data>
  <Data Name="HttpSubStatus">0</Data>
  <Data Name="ErrorCode">0</Data>
  <Data Name="ConfigExceptionInfo"></Data>
 </EventData>

So, I uninstalled the WebDAVModule from my IIS, everything is fine now~

The IIS tracing feature is very helpful.

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(179)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2018-12-17 Elasticsearch-->Get Started-->Basic concepts
2014-12-17 svn的分支
点击右上角即可分享
微信分享提示