【发布时间】:2021-08-19 11:09:14
【问题描述】:
我有一个具有以下声明的控制器
[Authorize(Roles = Role.Admin)]
[ApiController]
[Route("meta/[controller]")]
public class ActionParameterController : BaseController<ActionParameterController>
里面有如下方法
[HttpPost("insert/{action}/{entity}")]
public IActionResult InsertActionParameter(
[FromBody] MetaActionParameter parameter,
int action,
int entity)
但是,当我尝试向此端点发出 POST 请求时,我得到 404。 网址:
http://localhost:5000/meta/actionParameter/insert/2/2
控制台输出是:
2021-08-19 14:03:35.311 (Microsoft.AspNetCore.Hosting.Diagnostics.POST) [Information] Request starting HTTP/1.1 POST http://192.168.14.104:5000/meta/actionParameter/insert/1/2 - 0
2021-08-19 14:03:38.116 (Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.) [Verbose] All hosts are allowed.
2021-08-19 14:03:38.117 (Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.POST) [Debug] "POST" requests are not supported
2021-08-19 14:03:38.120 (Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.POST) [Debug] "POST" requests are not supported
2021-08-19 14:03:38.125 (Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.POST) [Debug] "POST" requests are not supported
2021-08-19 14:03:38.132 (Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.) [Debug] AuthenticationScheme: "Bearer" was not authenticated.
2021-08-19 14:03:38.180 (Microsoft.AspNetCore.Routing.Matching.DfaMatcher.) [Debug] No candidates found for the request path '"/meta/actionParameter/insert/1/2"'
2021-08-19 14:03:38.182 (Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.) [Debug] Request did not match any endpoints
2021-08-19 14:03:38.185 (Microsoft.AspNetCore.Server.Kestrel.) [Debug] Connection id ""0HMB303OBKKOL"" completed keep alive response.
2021-08-19 14:03:38.191 (Microsoft.AspNetCore.Hosting.Diagnostics.POST) [Information] Request finished HTTP/1.1 POST http://192.168.14.104:5000/meta/actionParameter/insert/1/2 - 0 - 404 0 - 2880.056
我尝试从IActionDescriptorCollectionProvider 获取所有路线并打印路线。该控制器中还有其他可以工作的路由。
如果我将路由更改为仅“插入”,请求就会通过。据我所知,路线之间没有冲突。
我应该采取哪些进一步的步骤来诊断这个问题?
【问题讨论】:
标签: c# asp.net-core