Web Api How to add a Header parameter for all API in Swagger

后端 未结 7 1064
温柔的废话
温柔的废话 2020-11-27 16:54

I searched for possible ways to add a request header parameter that would be added automatically to every method in my web-api but i couldn\'t find a clear one.

7条回答
  •  [愿得一人]
    2020-11-27 17:11

    Another way to add custom headers is by adding parameters into controller action.
    The following example will add x-test parameter to the UI:

    [HttpPost]
    public IActionResult Test([FromHeader(Name="x-test")][Required] string requiredHeader)
    {
        return Ok();
    }
    

提交回复
热议问题