我无法让 Gzip 压缩中间件在 asp.net core 2.0(或 2.1)中工作。我使用“Blank”Web 应用程序模板创建了一个新项目,并在 Startup.cs 中有以下代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseResponseCompression();
app.Run(async (context) =>
{
context.Response.Headers.Add("Content-Type", "text/plain");
await context.Response.WriteAsync("Hello World!");
});
}
Run Code Online (Sandbox Code Playgroud)
我确认 Chrome 在请求中发送了“Accept-Encoding: gzip, deflate, br”。
但是,服务器不会对响应进行 gzip 编码:
我究竟做错了什么?
我找到了这个讨论,并从那里尝试了一切,但没有帮助。