Error 405 - Methods not Allowed in ASP.NET Core PUT and DELETE requests

ASP.NET Core: Static Files cache control using HTTP Headers

A reader of my recent ASP.NET Core and Angular 2 book wrote me about a strange error occurred while publishing the OpenGameList Single-Page Application into production upon a Windows Server + IIS powered environment machine.

The published SPA seemed to be working OK at first, but when he logged in as Admin to update an item the command kept failing with the following message:

Error 405 - Methods not Allowed

I did my best to help him to troubleshoot the issue: after a few tests we found out that such error was coming out in response to any attempted PUT and DELETE request, while GET and POST methods were working fine.

Such weird discovery led me to dig through the web looking for a suitable explanation, until I eventually found the cause: it seems like the culprit is the WebDAVModule, which seems to set PUT and DELETE request methods disabled by default. In order to get them to work, we either need to change these defaults or disable it for the whole web application, which was what we did.

Here's what we put in the web.config file to remove it for good:

Despite the rather easy workaround, such an issue is definitely a though one, as it will easily affect most ASP.NET Core Web API and Web Applications when they get deployed on a live environment: that's because the WebDAV module, although not supported by IIS Express, happens to be enabled in most production servers. I guess that a lot of users will stumble upon it sooner or later... I definitely hope that this post will help some of them to overcome the hassle.

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

15 Comments on “Error 405 - Methods not Allowed in ASP.NET Core PUT and DELETE requests”

  1. Hola, gracias por la solucion, ahora tengo un problemas mas grande, trabajo con AWS y monto mi api en elastickbeanstalk, por lo que al momento de estar publicada mi API, no tengo una forma de agregar ese esa configuración, ahora la pregunta es si es posible modificar esta configuración con código.

  2. Pingback: ASP.NET Core Error 405 Methods not Allowed for PUT and DELETE requests when hosted on IIS – Mozartec
  3. Thank you very much! Nobody is talking about this issue and it took me nearly a whole day of playing around this behaviour until I found your post!

    1. Thank you for reading! :) If the post has been useful to you, don’t forget to like on FB/Twitter to help other developers find us as well :)

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.