0

What alternative do I have to avoid 405 Method Not Allowed error when using Put or Delete method in Web API?

I know there are a lot of solutions that specifically mention removing WebDAV from IIS, or disabling it from the Web.config, or other similar options For Example: "405 method not allowed" in IIS7.5 for "PUT" method and ASP.NET Web API - PUT & DELETE Verbs Not Allowed - IIS 8

But I have had multiple situations where these were either not viable solutions or they simply didn't work.

Pankwood
  • 1,799
  • 5
  • 24
  • 43
Oliver Moolman
  • 468
  • 5
  • 9
  • Shared environments for example where people are actually using WebDAV, but like I mentioned, that also did not work in some cases. – Oliver Moolman Jul 25 '18 at 13:13

1 Answers1

0

One alternative is to use Post instead of the Put or Delete method, you can do this by adding some decorators to the functions:

For Example:

    [HttpPost]
    [Route("api/Users/Update")]
    [ResponseType(typeof(void))]
    public IHttpActionResult PutUser(User user)
    {...

The [HttpPost] decorator just indicates that the function is a Post. And the Route is going to override the default routing in your WebApiConfig.cs.

I hope this makes it easier for someone in the future.

Oliver Moolman
  • 468
  • 5
  • 9