【发布时间】:2016-07-22 06:25:35
【问题描述】:
在此处使用 ASP.NET 4.6。
我有一个控制器:
public class ComputerController : ApiController
{
...
[HttpGet]
[Route("api/computer/ping")]
public IHttpActionResult Ping(int id)
{
return Ok("hello");
}
...
}
主要来自 this answer(查看 MSTdev 的回答),我的 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 }
);
路线不通。我总是得到
No HTTP resource was found that matches the request URI
'http://localhost:29365/api/computer/ping'.
这似乎是一个如此简单的问题,但我仍然很难过。有什么帮助吗?
【问题讨论】: