问题
I have a ASP.Net Core Web API project, and the following controller:
[Route("/api/v0.1/controller")]
[ApiController]
public class MyController : ControllerBase
{
[HttpGet("/test")]
public ActionResult Test() { return null; }
}
but when I run the project, at /api/v0.1/controller/test I get "page not found" and I don't see where I made a mistake.
回答1:
Your method route template contains prefixed /
, due to that, the app route couldn't find the appropriate path.
Modify test method route template as follows.
[HttpGet("test")]
public ActionResult Test() { return null; }
More at Routing to controller actions in ASP.NET Core
来源:https://stackoverflow.com/questions/58798420/asp-net-core-web-api-custom-route-not-working