Using Response Compression Middleware in ASP.NET Core
October 26, 2016 by Anuraj
C# ASP.NET Core Compression Middleware
This post is about using Response Compression Middleware in ASP.NET Core. Long back I wrote blog post on Enabling GZip Compression in ASP.NET5. It was a custom middleware I implemented in DNX days. Now as part of ASP.NET Core 1.1 Preview 1, Microsoft introduced Response Compression Middleware in ASP.NET Core.
To use Response Compression Middleware, first you need to add the Microsoft.AspNetCore.ResponseCompression
package to your project.json file.
You can enable compression using the Configure
and ConfigureServices
methods in the Startup.cs file.
Now you can restore the packages using dotnet restore
command, and run the application using dotnet run
command.
You can verify GZip compression enabled or not using Chrome developer tools. You can able to see something like this.
You can find more features and details about ASP.NET Core 1.1 Preview 1 release here
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub