You can just hi-jack the HttpContext
from the incoming Http Request
and add your own custom headers to the Response
object before calling return.
If you want your custom header to persist and be added in all API requests across multiple controllers, you should then consider making a Middleware
component that does this for you and then add it in the Http Request Pipeline in Startup.cs
public IActionResult SendResponse()
{
Response.Headers.Add("X-Total-Count", "20");
return Ok();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…