Two things.
First, when using routing based on conventions, more specific routes should appear before more general routes in order to avoid route conflicts.
app.UseMvc(routes => { routes.MapRoute(name: "api", template: "api/{controller=Admin}"); routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });
Secondly, you already use attribute routing on the controller, so you should have been redirected to the controller, except for the fact that you do not have a route pattern on the controller that would accept /api/{Controller}
This will require a default route.
[Route("api/[controller]")] public class AdminController : Controller { [HttpGet("")] //Matches GET api/admin <-- Would also work with [HttpGet] public IActionResult Get() { return Ok(); } [HttpGet("{id}")] //Matches GET api/admin/5 public IActionResult Get(int id) { return Ok("value"); } //...other code removed for brevity }
source share