C# ASP.Net核心Web API自定义路由不工作

C# ASP.Net核心Web API自定义路由不工作,c#,asp.net-core,asp.net-core-webapi,asp.net-core-routing,C#,Asp.net Core,Asp.net Core Webapi,Asp.net Core Routing,我有一个ASP.Net核心Web API项目和以下控制器: [Route("/api/v0.1/controller")] [ApiController] public class MyController : ControllerBase { [HttpGet("/test")] public ActionResult Test() { return null; } } 但是当我运行该项目时,在/api/v0.1/controller/test我得到了“未找到页面”,我不知道我在

我有一个ASP.Net核心Web API项目和以下控制器:

[Route("/api/v0.1/controller")]
[ApiController]
public class MyController : ControllerBase
{
   [HttpGet("/test")]
   public ActionResult Test() { return null; }
}

但是当我运行该项目时,在/api/v0.1/controller/test我得到了“未找到页面”,我不知道我在哪里犯了错误。

您的方法路由模板包含前缀
/
,因此,应用路由无法找到适当的路径

修改测试方法路线模板,如下所示

[HttpGet("test")]
public ActionResult Test() { return null; }  
更多