Check out this Post. They use a middleware approach which I just tested and it seems to be working. For asp.net core it would look like this:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.Debug);
app.Use(async (context, next) => {
context.Response.Headers.Remove("Content-Type");
context.Response.Headers.Add("Content-encoding", "gzip");
context.Response.Headers.Add("Content-Type", "application/json");
context.Response.Body = new System.IO.Compression.GZipStream(context.Response.Body, System.IO.Compression.CompressionMode.Compress);
await next();
await context.Response.Body.FlushAsync();
})
.UseMvc();
}
You can also try to play around with IResultFilter.OnActionExecuted as it is possible that the result is just not computed yet.