question

juanmaximilianoaguilarabanto-6444 avatar image
0 Votes"
juanmaximilianoaguilarabanto-6444 asked juanmaximilianoaguilarabanto-6444 answered

compression gzip in web api core doesn't work

Hi
I have the following code in the class startup...

using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace WebApplication3
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

     public IConfiguration Configuration { get; }

     // This method gets called by the runtime. Use this method to add services to the container.
     public void ConfigureServices(IServiceCollection services)
     {
         services.AddControllers();
         // Configure Compression level
         services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Optimal);

         // Add Response compression services
         services.AddResponseCompression(options =>
         {
             options.EnableForHttps = true;
             options.Providers.Add<GzipCompressionProvider>();
            // };
         });
     }

     // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
     public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
     {
         if (env.IsDevelopment())
         {
             app.UseDeveloperExceptionPage();
         }

         app.UseResponseCompression();

         app.UseHttpsRedirection();

         app.UseRouting();

         app.UseAuthorization();

         app.UseEndpoints(endpoints =>
         {
             endpoints.MapControllers();
         });

            

     }
 }

}

IIS Compression is enabled in IIS

101449-sin-titulo.png

When I call the service the gzip compresion doesn't work(IIS), it works only in IIS express..


dotnet-runtime
sin-titulo.png (15.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

juanmaximilianoaguilarabanto-6444 avatar image
1 Vote"
juanmaximilianoaguilarabanto-6444 answered

Hi
I found the solution

Gzip compression doesn't work in Windows 10 it works in windows servers versions

101746-untitled.png



untitled.png (60.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.