【发布时间】:2019-06-14 15:18:32
【问题描述】:
我调用了一个返回 404 Not found 的 ASP.Net Web API。控制器被识别,但未找到操作。
我尝试使用属性路由和[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 调用处理的字符串。
【问题讨论】:
标签: javascript c# jquery asp.net asp.net-web-api-routing