Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding header to action request and response

Tags:

c#

asp.net-mvc

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?

like image 762
Mario Dennis Avatar asked May 07 '26 05:05

Mario Dennis


1 Answers

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");
}
like image 177
Mihai Caracostea Avatar answered May 08 '26 19:05

Mihai Caracostea



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!