猿问

在 Swagger 中添加多个标题值

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


[HttpGet]

[Route("api/{bookID}")]

public async Task<IActionResult> GetBooksByID([FromHeader(Name = "Correlation-ID")]string bookID)

{

   //...

}

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


语法会是什么样子?


慕容708150
浏览 146回答 1
1回答

呼唤远方

只需添加更多参数,并FromHeader在要匹配的每个参数上包含属性:[HttpGet][Route("api/{bookID}")]public async Task<IActionResult> GetBooksByID(&nbsp; &nbsp; string bookID,&nbsp; &nbsp; [FromHeader(Name = "Correlation-ID")] string correlationID,&nbsp; &nbsp; [FromHeader(Name = "Tenant-ID")] string tenantID,&nbsp; &nbsp; [FromHeader(Name = "User-ID")] string userID){&nbsp; &nbsp;//...}
随时随地看视频慕课网APP
我要回答