【发布时间】:2018-09-13 11:56:32
【问题描述】:
我是 c# 和 web api 的新手。我有一个带有 Get 方法的 WebAPI 控制器,如下所示:
public class peopleController : ApiController
{
[HttpGet]
public IHttpActionResult getAllPeople(string Name, string Age)
{
//Return something
}
}
我的 WebApiConfig 是这样的:
config.Routes.MapHttpRoute(
name: "getAllPeopleApi",
routeTemplate: "people",
defaults: new { controller = "people", action = "getAllPeople" }
);
如果我这样调用我的网址:http://localhost:xxx/people?Name=&Age=。它工作正常。
但是当我像所有这些调用时:
http://localhost:xxx/people,http://localhost:xxx/people?Name=,http://localhost:xxx/people?Age=
我收到此错误消息:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:xxxx/......'.","MessageDetail":"No action was found on the controller 'people' that matches the request."}
我尝试设置我的routeTemplate: "people/{Name}/{Age}"。现在当我运行这个 web api Error 404.0 Not Found
【问题讨论】:
标签: c# asp.net-web-api routes