I make a call to an ASP.Net Web API which returns 404 Not found. The controller is recognized but the action is not found.
I have tried using attribute routing and [HttpGet]
for the action. I've also tried using standard API routing in the WebAPI config file. 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.
Make your GetEmployeeHierarchyList()
method int the controller public.