compression gzip in web api core doesn't work

juan maximiliano aguilar abanto 541 Reputation points
2021-06-01T20:56:37.56+00:00

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..

Developer technologies .NET .NET Runtime
0 comments No comments
{count} votes

Accepted answer
  1. juan maximiliano aguilar abanto 541 Reputation points
    2021-06-02T15:16:01.837+00:00

    Hi
    I found the solution

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

    101746-untitled.png

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.