我调用 ASP.Net Web API,该 API 返回 404 未找到。 Controller 已被识别,但未找到操作。
我尝试使用属性路由和 [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 调用处理的字符串。
最佳答案
将 Controller 中的 GetEmployeeHierarchyList()
方法公开。
关于javascript - 404 未找到 Web API 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56601070/