Working in ASP.NET 4.6 here.
I have a controller:
public class ComputerController : ApiController
{
...
[HttpGet]
[Route("api/computer/ping")]
public IHttpActionResult Ping(int id)
{
return Ok("hello");
}
...
}
Going mostly from this answer (look at MSTdev's answer), I have this in my WebApiConfig.cs
:
// So I can use [Route]?
config.MapHttpAttributeRoutes();
// handle the defaults.
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
The route doesn't work. I always get
No HTTP resource was found that matches the request URI
'http://localhost:29365/api/computer/ping'.
This seems like such a simple problem, yet I remain stumped. Any help?