我调用了一个ASP.Net Web,该API返回404NotFound。控制器被识别,但找不到动作。
我已经尝试使用属性路由和[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();
})我期望操作返回一个字符串,由fetch调用来处理。
发布于 2019-06-14 15:24:15
使您的GetEmployeeHierarchyList()方法在控制器中公开。
发布于 2019-06-14 16:12:59
,这应该很好:
[HttpGet]
[Route("api/User")]
public IHttpActionResult GetEmployeeHierarchyList()
{
// ...
return Json(results);
}https://stackoverflow.com/questions/56601070
复制相似问题