Add a custom response header in ApiController

后端 未结 6 1704
难免孤独
难免孤独 2021-02-05 02:41

Until now, I had a GET method that looked like the following:

protected override async Task GetAll(QueryData query)
{
              


        
6条回答
  •  野的像风
    2021-02-05 02:48

    You can use a custom ActionFilter that will allow you to send custom headers and access the HttpContext:

    public class AddCustomHeaderFilter : ActionFilterAttribute
    {
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
           actionExecutedContext.Response.Content.Headers.Add("name", "value");
        }
    }
    

提交回复
热议问题