404 未找到 Web API 路由
404 Not Found for Web API Route
我调用了 ASP.Net Web API,returns 404 Not found。已识别控制器,但未找到操作。
我已经尝试使用属性路由和 [HttpGet]
进行操作。我还尝试在 WebAPI 配置文件中使用标准 API 路由。我什至尝试过将两者结合起来。
//[HttpGet]
//[Route("api/User")]
protected IHttpActionResult GetEmployeeHierarchyList()
{
// ...
return Json(results);
}
config.Routes.MapHttpRoute(
name: "GetEmployeeHierarchyListTwo",
routeTemplate: "api/{controller}/{action}",
defaults: new { action = "GetEmployeeHierarchyList", }
);
return fetch("/api/User/" + api, {
method: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'credentials': 'include'
}
}).then(response => {
return response.json();
})
我希望对 return 字符串的操作由 fetch 调用处理。
使您的 GetEmployeeHierarchyList()
方法成为控制器 public。
这应该可以正常工作:
[HttpGet]
[Route("api/User")]
public IHttpActionResult GetEmployeeHierarchyList()
{
// ...
return Json(results);
}
我调用了 ASP.Net Web API,returns 404 Not found。已识别控制器,但未找到操作。
我已经尝试使用属性路由和 [HttpGet]
进行操作。我还尝试在 WebAPI 配置文件中使用标准 API 路由。我什至尝试过将两者结合起来。
//[HttpGet]
//[Route("api/User")]
protected IHttpActionResult GetEmployeeHierarchyList()
{
// ...
return Json(results);
}
config.Routes.MapHttpRoute(
name: "GetEmployeeHierarchyListTwo",
routeTemplate: "api/{controller}/{action}",
defaults: new { action = "GetEmployeeHierarchyList", }
);
return fetch("/api/User/" + api, {
method: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'credentials': 'include'
}
}).then(response => {
return response.json();
})
我希望对 return 字符串的操作由 fetch 调用处理。
使您的 GetEmployeeHierarchyList()
方法成为控制器 public。
这应该可以正常工作:
[HttpGet]
[Route("api/User")]
public IHttpActionResult GetEmployeeHierarchyList()
{
// ...
return Json(results);
}