I'm migrating a .NET 5.0.13 website to .NET 6, and am randomly getting "Failed to load resource: net::ERR_CONTENT_DECODING_FAILED" on some web pages. In one case, I could make the problem go away if I removed a couple of entries in a select list I was building, or by changing the underlying data in the database feeding the page.
Is anyone else seeing something like this?
I've used the Chrome debugger's network tab to look at what's being sent and a snippet looks like this:
"content": {
"size": 279890,
"mimeType": "text/html"
},
"redirectURL": "",
"headersSize": -1,
"bodySize": -1,
"_transferSize": 102,
"_error": "net::ERR_CONTENT_DECODING_FAILED"
},
How can I go about debugging this?
This is so random, I'm unable to produce a simple example, I'm afraid.
Thanks in advance!
------------ UPDATE -------------------------------
I believe the problem appears with VS2022, not .NET 6.
The problem was in our Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
};
We should have just gone with the default (false). Enabling compression for https also creates a security flaw.
Interestingly, with the EnableForHttps set to true, I could get things to work by forcing the compression to be GZIP:
services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<GzipCompressionProvider>();
});
.. or Brotli with 'optimized'
services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<BrotliCompressionProvider>();
});
services.Configure<BrotliCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Optimal;
});
but we're just going to turn EnableForHttps off.