I have a basic Web API controller built in MVC 6 (beta 3) as part of a new ASP.NET project. The problem I’ve come across is that it doesn’t accept the verbs PUT or PATCH and returns an error 404 whenever I try to access a URL with those methods.
Here’s what I’ve got as a basic 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!";
}
}
}
Visiting 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 a 404 with PUT and PATCH.
Edit:
I remember there being a way of enabling these verbs for MVC5 and lower that involved disabling WebDAV and adding handlers for the two verbs via web.config
, but as there’s no such thing as web.config
in ASP.NET 5 I’m at a total loss as to how to fix this. I’m assuming it’s probably solved via config.json
but all my attempts to search for this have returned nothing helpful at all!
A previous site I developed in MVC5 doesn’t have this problem, and having looked at the web.config
file there doesn’t appear to be anything in there that disables WebDAV (it’s actually uninstalled) or allows handling of PUT/PATCH methods for extensionless URLs. So I don’t think that what I wrote previously applies.
Any ideas?
Thanks
web.config support is only removed from the .NET and ASP.net part of the app. If your application is hosted in IIS, you still need a web.config just like you did for web API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With