Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET 5 + MVC 6 + Web API controller with PUT or PATCH verbs returns 404 error [closed]

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

like image 361
Dylan Parry Avatar asked Nov 01 '22 09:11

Dylan Parry


1 Answers

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.

like image 151
Yishai Galatzer Avatar answered Nov 08 '22 15:11

Yishai Galatzer