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

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>


WebDav-SchmebDav.. ..make sure you create the url with the ID correctly. Don't send it like http://www.fluff.com/api/Fluff?id=MyID, send it like http://www.fluff.com/api/Fluff/MyID.

Eg.

PUT http://www.fluff.com/api/Fluff/123 HTTP/1.1Host: www.fluff.comContent-Length: 11{"Data":"1"}

This was busting my balls for a small eternity, total embarrassment.


Add this to your web.config. You need to tell IIS what PUT PATCH DELETE and OPTIONS means. And which IHttpHandler to invoke.

<configuation>    <system.webServer>    <handlers>    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />    <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />    <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="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>    </system.webServer></configuration>

Also check you don't have WebDAV enabled.