首页 文章

在Azure上忽略ASP.NET Core的响应压缩中间件

提问于
浏览
0

我有一个简单的ASP.NET核心应用程序,在Startup.cs中我添加了响应压缩中间件,以便通过gzip压缩我的responeses - 超级简单 .

public void ConfigureServices(IServiceCollection services)
    {
        services.AddResponseCompression();
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseResponseCompression();

        app.UseStaticFiles();
        app.UseMvc(routeBuilder =>
        {
            var defaults = new { controller = "Views", action = nameof(ViewsController.Index) };
            routeBuilder.MapRoute("default", "{controller}/{action}/{id?}", defaults);
            routeBuilder.MapSpaFallbackRoute("spa-fallback", defaults);
        });
    }

在我的本地机器上,当我从Visual Studio启动App时,无论IISExpress或Project Command是否压缩了我的响应 .

enter image description here

现在我使用Visual Studio中的Publish-Command将我的ASP.NET核心应用程序发布到Azure,作为“Azure应用服务”,每个思考都像本地一样只有压缩而不是 .

enter image description here

有没有人知道我错过了什么?

--- UPDATE ---

好的,我使用Visual Studio创建了一个空的.Net Core Web应用程序 . 我编辑Startup.cs看起来像这样,并将一个简单的index.html放在wwwroot文件夹中 . 然后我右键单击该项目并选择部署选项 . 我使用新的Resourcegroup,新计划和新的AppService创建了一个新的配置文件 .

结果如下:http://gzipapptest.azurewebsites.net/index.html但是chrome / fiddler show没有gzip - 也许是因为公司代理可以试试这个网站吗?

谢谢,iBot

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
    services.AddResponseCompression();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseResponseCompression();

    app.UseStaticFiles();
}

}

1 回答

  • 1

    我用你提到的代码测试它,它在我身边正常工作 . 并且很奇怪你提到了远程地址的sceenshot: 127.0.0.1:8888. 如果有可能请尝试创建一个新的WebApp并进行部署 .

    enter image description here

    Updated:

    它也适用于您的WebApp,您可以参考屏幕 . 如果在响应头中没有看到gzip,我认为它是从缓存中收到的 .

    enter image description here

    Received from cache

    enter image description here

相关问题