【问题标题】:Web API "Nested" Route?Web API“嵌套”路由?
【发布时间】:2020-04-21 20:04:15
【问题描述】:

这里没有真正的代码,但正在寻找方向。我正在使用.net core web api。出现了一个潜在的要求,即为基于用户的 api 使用某种嵌套路由。

即:https://blah.com/controller/YourNameHere/variable

这可能吗?

我在控制器中习惯了这种格式:

[ApiController]
[Route("api/[controller]")]

我也相信您可以指定静态路由,例如 /api/[controller]/somethingstatic/id。

【问题讨论】:

    标签: .net asp.net-core asp.net-core-webapi asp.net-web-api-routing


    【解决方案1】:

    您可以通过使用 HttpGet 前缀指定您使用的 ControllerMethods 上的路由:例如:

    [HttpGet("StageResult/{name}/something/{id}")]
    public ActionResult<IEnumerable<TeamResultsDTO>> GetStageResults(string name, int id){ ... 
    
    

    这里解释的更清楚: How to pass multiple parameters to a get method in ASP.NET Core

    【讨论】:

    • 工作就像一个魅力。谢谢!
    猜你喜欢
    • 2013-01-13
    • 1970-01-01
    • 2016-01-10
    • 1970-01-01
    • 2020-07-18
    • 2021-08-13
    • 2011-10-10
    • 2018-05-29
    • 2017-10-31
    相关资源
    最近更新 更多