我知道如何在Swagger中添加一个标头值,这是代码:
[HttpGet]
[Route("api/{bookID}")]
public async Task<IActionResult> GetBooksByID([FromHeader(Name = "Correlation-ID")]string bookID)
{
//...
}
但是,如果我想添加其他标头值,例如“ TenantID”,“ UserID”等,该怎么办?
语法如何?
答案 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)
{
//...
}