Mario Dennis
Mario Dennis

Reputation: 3016

Adding header to action request and response

How can I add a HTTP header to all action calls in ASP.NET MVC. Looking at the IActionFilter but could I interact with the HttpRequestMessage instance if I was to use it?

Upvotes: 3

Views: 3789

Answers (1)

Mihai Caracostea
Mihai Caracostea

Reputation: 8466

In your IActionFilter, you provide the OnActionExecuted method where you could do something like this:

void OnActionExecuted(ActionExecutedContext filterContext)
{
    filterContext.HttpContext.Response.Headers.Add("Header-Name", "HeaderValue");
}

Upvotes: 4

Related Questions