如何在api控制器中获取所有操作的完整网址

时间:2019-07-18 12:04:32

标签: c# url asp.net-web-api

我有一个控制器,应该返回同一控制器中其他Action的完整URL。我不知道该怎么做。请看我的示例(使用伪结果):

[Route("api/v{api-version:apiVersion}/Tests")]
[ApiController][AllowAnonymous]
public class TestsController : ControllerBase
{
    [HttpGet]
    public async Task<IActionResult> GetActions()
    {
        var idDemo = 1;

        //TODO         
        urls.Add("Get full url for Call method with parameter : idDemo ");
        urls.Add("Get full url for Something method with parameter : idDemo ");

        return Ok(urls);
    }

    [HttpPost("call/{id}")]
    public async Task<IActionResult> Call(int id)
    {
         return Ok();
    }

    [HttpPost("do/it/{id}")]
    public async Task<IActionResult> Something(int id)
    {
        return Ok();
    }
}

0 个答案:

没有答案