[英]404 Not Found for Web API Route
I make a call to an ASP.Net Web API which returns 404 Not found. 我对返回404 Not found的ASP.Net Web API进行了调用。 The controller is recognized but the action is not found.
控制器已识别,但未找到操作。
I have tried using attribute routing and [HttpGet]
for the action. 我尝试使用属性路由和
[HttpGet]
进行操作。 I've also tried using standard API routing in the WebAPI config file. 我还尝试过在WebAPI配置文件中使用标准API路由。 I've even tried combining the two.
我什至尝试将两者结合。
//[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();
})
I expect the action to return a string to be handled by the fetch call. 我希望该操作返回由提取调用处理的字符串。
使您的GetEmployeeHierarchyList()
方法在控制器中公开。
This should workfine: 这应该工作良好:
[HttpGet]
[Route("api/User")]
public IHttpActionResult GetEmployeeHierarchyList()
{
// ...
return Json(results);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.