.NET 11 Preview - Disabling Zstandard Compression in Kestrel
[C#, .NET, .NET 11 Preview, ASP.NET]
In yesterday’s post, “.NET 11 Preview - Enabling Zstandard Compression in Kestrel”, we looked at how to enable Zstandard content compression in Kestrel.
In this post, we will look at how to turn it off.
The simplest way is to not configure this feature in the middleware.
In other words, instead of this:
var builder = WebApplication.CreateBuilder(args);
// Register the response compression services
builder.Services.AddResponseCompression();
var app = builder.Build();
// Turn on the middleware
app.UseResponseCompression();
// Register a route
app.MapGet("/Hello", () => "The quick brown fox jumped over the lazy dog");
// Start the application
app.Run();
Your setup should look like this:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Register a route
app.MapGet("/Hello", () => "The quick brown fox jumped over the lazy dog");
// Start the application
app.Run();
This is the simplest option, and here you will get no content compression at all.
The more sophisticated way is to selectively enable the compression algorithms that you want.
The code will look like this:
using Microsoft.AspNetCore.ResponseCompression;
var builder = WebApplication.CreateBuilder(args);
// Register the response compression services
builder.Services.AddResponseCompression(options =>
{
//
// Remove all the providers
//
options.Providers.Clear();
//
// Add back the ones we want
//
// First, brotli
options.Providers.Add<BrotliCompressionProvider>();
// Next, gzip
options.Providers.Add<GzipCompressionProvider>();
});
var app = builder.Build();
// Turn on the middleware
app.UseResponseCompression();
// Register a route
app.MapGet("/Hello", () => "The quick brown fox jumped over the lazy dog");
// Start the application
app.Run();
Here we are doing the following:
- Removing all compression providers
- Re-registering the ones we want to use
- We are explicitly not adding the
Zstandardcompression provider
We can verify that the compression works.
Brotli:

Gzip

Zstandard is not compressed:

TLDR
You can control whether or not to use Zstandard compression in Kestrel.
The code is in my GitHub.
Happy hacking!