I have a WebAPI controller that returns an HttpResponseMessage
and I want to add gzip compression. This is the server code:
using System.Net.Http;
u
Add these NuGet packages:
Microsoft.AspNet.WebApi.Extensions.Compression.Server System.Net.Http.Extensions.Compression.Client
Then and add one line of code to App_Start\WebApiConfig.cs
:
GlobalConfiguration.Configuration.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor()));
That will do the trick!
Details at:
Hope that helps.
**Updated after comment from @JCisar
Update for ASP.Net Core
Nuget Package is
Microsoft.AspNetCore.ResponseCompression