ASP.Net Core Web API自定义路由不起作用

Eutherpy

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

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

但是当我运行该项目时,在/api/v0.1/controller/test上我得到“找不到页面”,并且看不到我在哪里出错。

yang阳德赛

您的方法路由模板包含prefixed /,因此,应用程序路由找不到合适的路径。

如下修改测试方法路由模板。

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

更多内容 Routing to controller actions in ASP.NET Core

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Web API的ASP.Net Core路由

ASP.NET Core Web API:捕获路由错误

在ASP.NET MVC Core Web API和Entity Framework Core中使用TryUpdateModel更新模型不起作用

ASP.Net Core Web Api中的异步视频流不起作用

基于ASP.Net Core Web API约定的路由?

ASP.NET Core-自定义AspNetCore.Identity实现不起作用

自定义身份验证ASP.NET Core Web API

ASP.NET Core Web API中用于整数值的自定义模型验证器

ASP.NET Core处理Web API中的自定义响应/输出格式的方法

如何在Swashbuckl ASP.NET Core Web API上添加自定义标头

是否可以将路由值绑定到ASP.NET Core Web API中的自定义属性的属性?

返回的自定义状态代码在ASP.Net Web API中不起作用

ASP.NET Core Web API自动JSON参数反序列化不起作用

Asp.net Core 2.1 Web API中的自定义授权

自定义AuthenticationHandler在Asp.Net Core 3中不起作用

ASP.NET Core 3 Web Api发布请求不起作用

JWT承载令牌授权不起作用ASP Net Core Web API

ASP.NET Core 3.1 Web API基于角色的授权不起作用

ASP.NET Core自定义中间件重定向到操作不起作用

自定义授权筛选器在ASP.NET Core 3中不起作用

ASP Net Core Web API自定义模型验证

ASP.NET Web API 自定义发布操作不起作用

Asp.net Core Api 自定义路由

ASP.NET Core 中的自定义路由

调试asp.net core web API

Asp.Net Core 3.0 自定义控件验证不起作用

ASP.NET Core 3.1 Web API - 自定义 json

ASP.NET Core Web API 常规路由

ASP.NET Core 中的属性路由不起作用