I have built some API endpoints using ASP.NET Web API. When i tried to do PUT or DELETE request, got 405 Method Not Allowed error. But it is working fine for GET and POST request.
Interestingly, PUT and DELETE is working nicely when i have hosted the project in local IIS. It's only throwing 405 error in the DEV server.
In my web.config:
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
</system.webServer>
What am i missing here? Thanks in advance.
If you are using Visual Studio 2012 or later to develop a Web API application, IIS Express is the default web server. This web server is a scaled-down version of the full IIS functionality that ships in a server product, and this web server contains a few changes that were added for development scenarios. For example, the WebDAV module is often installed on a production web server that is running the full version of IIS, although it may not be in actual use.
The development version of IIS, (IIS Express), installs the WebDAV module, but the entries for the WebDAV module are intentionally commented out, so the WebDAV module is never loaded on IIS Express. As a result, your web application may work correctly on your local computer, but you may encounter HTTP 405 errors when you publish your Web API application to your production web server.
Since your DEV server has full IIS functionality (with WebDAV) it will register multiple handlers for the same verb/method and one of the handlers is blocking the expected handler from processing the request.
So, the WebDAV is overriding your HTTP PUT and DELETE. During the processing of an HTTP PUT request, IIS calls the WebDAV module, When the WebDAV module is called, it checks its configuration and sees it is disabled, so it will return HTTP 405 Method Not Allowed error for any request that resembles a WebDAV request.
You can read more here https://learn.microsoft.com/en-us/aspnet/web-api/overview/testing-and-debugging/troubleshooting-http-405-errors-after-publishing-web-api-applications
To disable WebDAV add the following into your web.config
<system.webServer>
<modules>
<remove name="WebDAVModule"/>
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>