我知道如何在Swagger中添加一个头值,下面是代码:
[HttpGet] [Route("api/{bookID}")] public async Task<IActionResult> GetBooksByID([FromHeader(Name = "Correlation-ID")]string bookID) { //... }
但如果我愿意 添加其他标题值 ,如“TenantID”、“UserID”等。
语法看起来怎么样?
只需添加更多参数,并包括 FromHeader 要匹配的每个参数的属性:
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) { //... }