本文介绍了ASP.Net Core Web API自定义路由不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ASP.Net Core Web API项目和以下控制器:
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; }
}
但是当我运行项目时,在/api/v0.1/controller/test 上,我看到找不到页面",并且看不到我在哪里出错.
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.
推荐答案
您的方法路由模板包含带前缀的/
,因此,应用程序路由找不到合适的路径.
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; }
更多信息,请访问 路由到ASP.NET Core中的控制器操作
More at Routing to controller actions in ASP.NET Core
这篇关于ASP.Net Core Web API自定义路由不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!