Mozart Al Khateeb

Full Stack

Mobile

.Net Developer

ERP Developer

Mozart Al Khateeb

Full Stack

Mobile

.Net Developer

ERP Developer

Blog Post

ASP.NET Core Error 405 Method not Allowed for PUT and DELETE requests when hosted on IIS

April 8, 2019 Hosting
ASP.NET Core Error 405 Method not Allowed for PUT and DELETE requests when hosted on IIS

This error could foul you by showing two responses from the IIS

  • 405 method not allowed
  • (No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:4200’ is therefore not allowed access.)

Actually this has nothing to do with cors since when i had this issue i have already configured cors and it was working fine with POST and GET Methods. and the pain happens when your logging service does not capture any error.

I figured out the solution after two days of research and it was a problem with IIS Itself with the
WebDAVModule which seems to block PUT and DELETE methods by default and i found the solution in the following article.

All you have to do is to add the following code to the web.config:

<system.webServer>
  <modules runAllManagedModulesForAllRequests="false">
    <remove name="WebDAVModule" />
  </modules>
</system.webServer>
Taggs:
15 Comments
  • Sam 5:45 pm October 20, 2020 Reply

    You saved me hours of debugging, Thank you

    • SAQLAIN SHABIR 12:49 am September 4, 2021 Reply

      from where we put this code in dot net core project because in dot net core project we have appsetting.json file.In the dot net core project we have no file like web config. please reply thank you

  • Paulo Pereira 8:08 pm November 6, 2020 Reply

    Thank you!

  • Packers and Mvers in Dombivli 2:33 pm December 5, 2020 Reply

    fantastic post, very informative. I wonder why the other experts of this sector don’t notice this. You must continue your writing. I am confident, you have a huge readers’ base already!

  • Packers and Mvers in Mulund 12:12 am December 6, 2020 Reply

    Hey There. I found your blog using msn. This is a really well written article. I’ll make sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely comeback.

  • Ali 7:19 pm December 21, 2020 Reply

    Thanks man
    that solved my problem nicely

  • Bikram Keshari Sahu 7:53 am December 30, 2020 Reply

    It did helped. Thanks a lot!

  • Ivan 8:01 pm January 20, 2021 Reply

    Great, thanks a lot!

  • Alex 8:58 pm April 3, 2021 Reply

    I have read more posts about dealing with ‘405 errors’ for PUT and DELETE requests on .Net Core 3.1 than I care to mention. This was the silver bullet. Thank you VERY much for sharing this.

  • Mostafa khairy 5:05 pm April 22, 2021 Reply

    Thanks alot

  • Ivica Buljevic 10:34 pm July 9, 2021 Reply

    This didn’t solved my problem (dotnet core 3.1). For several years I run app on Linux Fedora, but now I wanted to run it on Windows Server 2016 and got this error: 405 method not allowed…

  • Ivica Buljevic 11:35 pm July 9, 2021 Reply

    continue on my previous post:
    finally solved problem: go to IIS options – Common HTTP Features – removed WebDAV Publishing

    • Mozart Al Khateeb 8:35 pm July 26, 2021 Reply

      Sure one solution is to remove WebDav but this solution is for those who wanna keep it.
      I don’t know why this solution did not work for you, I’ve applied it to multiple servers and PCs, maybe you needed to restart IIS.

  • SAQLAIN SHABIR 12:50 am September 4, 2021 Reply

    from where we put this code in dot net core project because in dot net core project we have appsetting.json file.In the dot net core project we have no file like web config. please reply thank you

    • Mozart Al Khateeb 10:11 pm October 5, 2021 Reply

      You can create web.config yourself, this is required for IIS to override specific attributes, check this link to learn more about this file

Write a comment