在Swagger中添加多个标题值

时间:2018-08-08 22:55:01

标签: c# api asp.net-core header swagger

我知道如何在Swagger中添加一个标头值,这是代码:

[HttpGet]
[Route("api/{bookID}")]
public async Task<IActionResult> GetBooksByID([FromHeader(Name = "Correlation-ID")]string bookID)
{
   //...
}

但是,如果我想添加其他标头值,例如“ TenantID”,“ UserID”等,该怎么办?

语法如何?

1 个答案:

答案 0 :(得分:3)

只需添加更多参数,并在您要匹配的每个参数上包含FromHeader属性:

[HttpGet]
[Route("api/{bookID}")]
public async Task<IActionResult> GetBooksByID(
    string bookID,
    [FromHeader(Name = "Correlation-ID")] string correlationID,
    [FromHeader(Name = "Tenant-ID")] string tenantID,
    [FromHeader(Name = "User-ID")] string userID)
{
   //...
}