ASP.NET Core 1.1 has an inbuilt Response Compression Middleware for compression, which by default uses GZIP compression. In simple words, GZIP is a technique, which is used for the file compression and decompression for faster network transfer.
All the modern Browsers support response compression. Using GZIP Compression is the best approach to reduce the response size and provide better speed for transferring the files over the network.
Enable GZIP compression in ASP.NET Core
Let's first install GZIP in our ASP.NET MVC Project, using NUGET Package Manager.
Step 1
Right click on ASP.NET Core and select Manage Nuget Package.
Enable GZIP compression in ASP.NET Core
Let's first install GZIP in our ASP.NET MVC Project, using NUGET Package Manager.
Step 1
Right click on ASP.NET Core and select Manage Nuget Package.

Step 2
Browse Microsoft.AspNetCore.ResponseCompression.
Once ResponseCompression is installed, we need to configure it.
Let's open Startup.cs file and add the code given below in ConfigurationService method.

Code snippet
Browse Microsoft.AspNetCore.ResponseCompression.
Once ResponseCompression is installed, we need to configure it.
Let's open Startup.cs file and add the code given below in ConfigurationService method.

Code snippet
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- // Add framework services.
- services.AddDbContext<ApplicationDbContext>(options =>
- options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
- services.AddIdentity<ApplicationUser, IdentityRole>()
- .AddEntityFrameworkStores<ApplicationDbContext>()
- .AddDefaultTokenProviders();
- //Add ResponseCompression as Service
- services.AddResponseCompression();
- services.AddMvc();
- // Add application services.
- services.AddTransient<IEmailSender, AuthMessageSender>();
- services.AddTransient<ISmsSender, AuthMessageSender>();
- }
By default, ASP.NET Core uses GZIP compression. Now, let’s add this middleware to HTTP pipeline, so add the line of code given below in Configure method of Startup.cs.
Remember to add Compression middleware before other middlewares, which serves the files.
Code snippet
Remember to add Compression middleware before other middlewares, which serves the files.
Code snippet



Harish PaudelPosted Apr 26, 2020, 8:34 AM
10x friend new thing i learn today from your articles, thanks once again for your efforts.
Parth AkbariPosted Oct 17, 2018, 12:33 AM
I want to compress file and sent it to browser. is it possible? if yes, then browser download that file so, it will decompress it or not?
Ryan BattistonePosted Feb 13, 2018, 12:20 PM
This is actually a very vulnerable method. Do not use this, unless your website is static, and does not use any sort of password or login authentication, any kind of API tokens, etc. https://security.stackexchange.com/questions/19911/crime-how-to-beat-the-beast-successor/19914