I have used response.AppendHeader("Content-encoding", "gzip"); inside a OnResultExecuting() method of a class that derives ActionFilterAttribute. But it returns an error like:
//HttpResponseBase response = filterContext.HttpContext.Response;
HttpResponse response = filterContext.HttpContext.Response;
response.AppendHeader("Content-encoding", "gzip");
'HttpResponse' does not contain a definition for 'AppendHeader' and no accessible extension method 'AppendHeader' accepting a first argument of type 'HttpResponse' could be found (are you missing a using directive or an assembly reference?)
The ASP.NET Core response headers use properties to represent most of the common headers.
To set the content encoding in .NET 6, use:
response.Headers.ContentEncoding = "gzip";
For earlier versions, you'll need to use the Append extension method:
response.Headers.Append("Content-Encoding", "gzip");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With