【发布时间】:2023-03-31 08:01:02
【问题描述】:
我有一个简单的 ASP.NET Core 应用程序,并在 Startup.cs 中添加了响应压缩中间件,以通过 gzip 压缩我的响应 - 超级简单。
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 启动应用程序时,无论是 IISExpress 还是 Project Command,我的响应都被压缩了。
现在我使用 Visual Studio 中的 Publish-Command 将我的 ASP.NET Core 应用程序作为“Azure 应用程序服务”发布到 Azure,每个想法都像本地一样工作,只是压缩不是。
有人知道我错过了什么吗?
---更新---
好的,我用 Visual Studio 创建了一个空的 .Net Core Web 应用程序。我将 Startup.cs 编辑为如下所示,并将一个简单的 index.html 放在 wwwroot 文件夹中。比我右键单击项目并选择部署选项。我创建了一个包含新资源组、新计划和新 AppService 的新配置文件。
结果如下:http://gzipapptest.azurewebsites.net/index.html 但是 chrome/fiddler 节目没有 gzip - 可能是因为公司代理,你可以试试这个网站吗?
谢谢,iBot
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddResponseCompression();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseResponseCompression();
app.UseStaticFiles();
}
}
【问题讨论】:
-
我发现它在您提供的站点中有效。我会更新我的答案。
-
如果有用,请将其标记为答案,以帮助更多有相同问题的社区。span>
标签: asp.net azure-web-app-service