Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
[HttpPut]
public async Task<IActionResult> CreatePerson([FromBody]CreatePersonCommand command, [FromHeader(Name = "x-requestid")] string requestId)
This is a web api method, which is accessed by another project.
The client code looks like this:
var response = await _httpClient.PutAsync(uri, personContent);
Is it possible to access the x-requestid at the client in the response that is sent from the web api project?
–
In case you need to get value:
var response = await _httpClient.PutAsync(uri, personContent);
response.Headers.TryGetValues("x-requestid", out var headerValues);
If you need to add headers to the response in your Web API, you have access to Response
entity in your controller which inherits from ASP ControllerBase
class:
Response.Headers.Add("x-requestid", "value");
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.