GZIP in .net core not working

后端 未结 7 977
不思量自难忘°
不思量自难忘° 2021-02-03 22:38

I\'m attempting to add Gzip middleware to my ASP.net core app.

I have added the following package :

\"Microsoft.AspNetCore.ResponseCompression\"

7条回答
  •  梦谈多话
    2021-02-03 22:56

    To Enable GZIP in .net core 2.*
    1. Install Microsoft.AspNetCore.ResponseCompression with Install-Package Microsoft.AspNetCore.ResponseCompression command or nuget package manager.
    2. Add the following code into Startup.cs

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
    
      app.UseResponseCompression();
      app.UseMvc();
    
    }
    
    public void ConfigureServices(IServiceCollection services)
    {
    
      // Configure Compression level
      services.Configure(options => options.Level = CompressionLevel.Fastest);
    
      // Add Response compression services
      services.AddResponseCompression(options =>
      {
          options.Providers.Add();
          options.EnableForHttps = true;
      });
    
    }
    

提交回复
热议问题