ASP.NET 5 + MVC 6 + API Controller with PUT or PATCH API Returns 404 Error

I have a basic web API controller created in MVC 6 (beta 3) as part of a new ASP.NET project. The problem I am facing is that it does not accept PUT or PATCH verbs and returns a 404 error whenever I try to access a URL with these methods.

Here is what I got as the main test:

namespace Test.Controllers { [Route("api/test")] public class TestController : Controller { [HttpGet] public string TestGet() { return "Hello from GET!"; } [HttpPost] public string TestPost() { return "Hello from POST!"; } [HttpDelete] public string TestDelete() { return "Hello from DELETE!"; } [HttpPut] public string TestPut() { return "Hello from PUT!"; } [HttpPatch] public string TestPatch() { return "Hello from PATCH!"; } } } 

A visit to http://localhost/api/test with "Postman" to check the URL with each of the verbs (GET, POST, DELETE, PUT and PATCH), in turn, works fine for GET, POST and DELETE, but gives 404 with PUT and PATCH.

Edit: I remember that there is a way to enable these verbs for MVC5 and below, which is related to disabling WebDAV and adding handlers for two verbs via web.config , but since ASP.NET 5 there is no such thing as web.config complete loss regarding how to fix it. I assume that it was probably resolved through config.json , but all my attempts to find this did not return anything useful!

On the previous site that I developed in MVC5, this problem does not occur, and looking at the web.config , there is nothing that disables WebDAV (it is actually deleted) or allows you to process the PUT / PATCH methods for an unlimited URL. Therefore, I do not think that what I wrote earlier applies.

Any ideas?

thanks

+5
source share
1 answer

Web.config support is only removed from part of the .NET application and ASP.net. If your application is hosted in IIS, you still need web.config, just like for the web API.

+2
source

Source: https://habr.com/ru/post/1214612/


All Articles