在 Swagger 中添加多个标头值

问题描述 投票:0回答:1

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

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

但是如果我想添加额外的标头值,例如“TenantID”、“UserID”等,该怎么办

语法是什么样的?

c# asp.net-core swagger http-headers
1个回答
5
投票

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

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)
{
   //...
}
© www.soinside.com 2019 - 2024. All rights reserved.