I read a lot of topics about API routes in the Asp.net core, but I can't get it to work.
Firstly, this is my controller:
Public class BXLogsController : Controller { //[HttpGet("api/[controller]/ID/{id}", Name = "GetL")] public IActionResult GetById(string id) { if (id.Trim() == "") return BadRequest(); else { Logs l = AccessBase.AccBase.GetLog(id); return Json(l); } } //[HttpGet("api/[controller]/API/{apiname}", Name = "GetLAPI")] public IActionResult GetByAPI(string apiname) { if (apiname.Trim() == "") return BadRequest(); else { List<Logs> lstLogs = AccessBase.AccBase.GetLogsApi(apiname); return Json(lstLogs); } } }
I tried to use HttpGetAttribute
with a path (see Comment), but this does not work.
Therefore, I want to use the MapRoute
approach MapRoute
but this does not work either.
app.UseMvc(routes => { routes.MapRoute( name: "LogsId", template: "api/[controller]/ID/{id}", defaults: new { controller = "BXLogs", action = "GetById" }); routes.MapRoute( name: "LogsAPI", template: "api/[controller]/API/{apiname}", defaults: new { controller = "BXLogs", action = "GetByAPI" }); });
I must have forgotten something, but I canβt see anything.
Can anybody help me?
source share