【发布时间】: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