【问题标题】:GZip For ASP.NET WebAPI用于 ASP.NET WebAPI 的 GZip
【发布时间】:2018-12-22 23:03:05
【问题描述】:

我正在使用Plugin 对 ASP.NET WebAPI 响应进行 GZIP 压缩。

问题:

报错如下:

找不到类型或命名空间名称“GZipCompressor”(您是否缺少 using 指令或程序集引用?)

我已经添加了Packages并在“Global.asax.cs”文件下使用方法:**Application_Start()

我尝试了什么:

在“Global.asax.cs”文件中添加了以下命名空间:

using Microsoft.AspNet.WebApi.Extensions.Compression.Server;
using System.Net.Http.Extensions.Compression.Client;

注意:命名空间using System.Net.Http.Extensions.Compression.Client; 未得到解析。

这意味着如果我在 Visual Studio 中键入 System.Net.Http,我可以在 Global.asax.cs

中获得 Http 命名空间

我的 Application_Start 方法:

protected void Application_Start(object sender, EventArgs e)
{
   // Code that runs on application startup
   BundleConfig.RegisterBundles(BundleTable.Bundles);

   GlobalConfiguration.Configure(WebApiConfig.Register);

   GlobalConfiguration.Configuration.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor()));
}

.NET Framework 版本为 4.6.1

有没有其他方法可以在不使用插件的情况下使用 GZIP 压缩 WebAPI 结果?

【问题讨论】:

    标签: c# asp.net-web-api asp.net-web-api2 gzip


    【解决方案1】:

    我去插件项目链接安装了

    我添加了你提到的那行GlobalConfiguration.Configuration.MessageHandlers.Insert(0, new ServerCompressionHandler(new GZipCompressor(), new DeflateCompressor()));

    它没有编译。但我确实必须在 Global.asax.cs 中添加以下 using 语句

    using Microsoft.AspNet.WebApi.Extensions.Compression.Server;
    using System.Net.Http.Extensions.Compression.Client;
    using System.Net.Http.Extensions.Compression.Core.Compressors;
    

    然后编译。我不知道这是否能回答你的问题......但我希望它会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 2014-09-09
      • 2014-11-30
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多