Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hey,
I am running .NET 5 and Umbraco 9.2.0 for my project. I am trying to create an API controller but I am only getting 404. The path I'm using is https://localhost:44349/umbraco/api/locations/getalllocations
I made sure that the controller is being compiled as well. Any help would be appreciated.
public class LocationsController : UmbracoApiController { private readonly ILogger<LocationsController> logger; private readonly LocationsAPIService locationsAPIService; public LocationsController( ILogger<LocationsController> logger, LocationsAPIService locationsAPIService ) { this.logger = logger; this.locationsAPIService = new LocationsAPIService(new LocationAPISettingsFactory().Build()); } public IEnumerable<string> GetAllLocations() { return new[] { "Table", "Chair", "Desk", "Computer" }; } }
Hello, saitejkancharla.
Just just stumple over the same isssue in umbraco 10. The solution was the return type
So instead of
public IEnumerable<string> GetAllLocations() { return new[] { "Table", "Chair", "Desk", "Computer" }; }
try it out where it is this
public ActionResult<IEnumerable<string>> GetAllLocations() { return new[] { "Table", "Chair", "Desk", "Computer" }; }
I tried returning ActionResult and IActionResult and both still return 404 error. I am not sure what I should be doing. I tried giving routes to the method and it still doesn't work.
you don't need to use ActionResult
Just ran a quick test in my DEV system and it worked OK. Have you changed or added anything in startup.cs that may affect it?
I wasnt able to figure out why it didnt work but I deleted all my changes and redid them again and it started working. Go figure
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
UmbracoApiController 404 Error .Net 5 Umbraco 9
Hey,
I am running .NET 5 and Umbraco 9.2.0 for my project. I am trying to create an API controller but I am only getting 404. The path I'm using is https://localhost:44349/umbraco/api/locations/getalllocations
I made sure that the controller is being compiled as well. Any help would be appreciated.
Hello, saitejkancharla.
Just just stumple over the same isssue in umbraco 10. The solution was the return type
So instead of
try it out where it is this
I tried returning ActionResult and IActionResult and both still return 404 error. I am not sure what I should be doing. I tried giving routes to the method and it still doesn't work.
you don't need to use ActionResult
Just ran a quick test in my DEV system and it worked OK. Have you changed or added anything in startup.cs that may affect it?
I wasnt able to figure out why it didnt work but I deleted all my changes and redid them again and it started working. Go figure
is working on a reply...