ASP.NET Core Web API PUT and DELETE Methods not allowed (405 Error)

When Deployed to Live Environment

Ran into this issue after deploying our latest web app built on ASP.NET 5 (now known as Core 1.0), MVC 6 with Web API.

We are using HostForLife shared servers to host the site, a solid yet inexpensive choice for any of you looking for hosting recommendations.

We found that both GET and POST methods worked fine but neither PUT or DELETE worked at all. We were getting a 405 Method Not Allowed error.

From reading up on this it seems to be to do with something called WebDav disallowing these action names by default. You will need to override this setting in order to get it to work.

To do this open up your web.config file. There are 2 web.config files in your project – The one you want to open is the one INSIDE the wwwroot folder.

Inside the web.config add the following 3 lines inside the already existing system.webServer node:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="false">
    <remove name="WebDAVModule" />
  </modules>
</system.webServer>

Now just save your file and publish changes to your live site.

Update: Changes in ASP.NET Core 2.0 and Visual Studio 2017

It has recently come to my attention that in some of the newer project templates in Visual Studio 2017 (sidenote: if you haven’t moved from 2015 to 2017 yet then you should, it can be downloaded here) there is in fact no web.config file inside the wwwroot folder. One of the commenters below has mentioned that they just put the above code into the web.config file that was still there outside of the wwwroot folder at the project root level and that it worked fine there also.

I have also seen some newer project templates (as of April 2018) that did not include any web.config file at all. From what I have read there is a push to replace web.config files with appsettings.json files. In this instance I’m not actually sure what best practice is, as I have yet to deploy one of these newer ASP.NET Core websites. If anyone has any ideas let me know. My gut tells me that adding a web.config file yourself and adding in the code there should work fine, but as I said, there may be a newer, better way to do it in 2.0.

3 Responses to “ASP.NET Core Web API PUT and DELETE Methods not allowed (405 Error)”