相关疑难解决方法(0)

如何在ASP.NET中实现GZip压缩?

我正在尝试为我的asp.net页面实现GZip压缩(包括我的CSS和JS文件).我尝试了以下代码,但它只压缩我的.aspx页面(从YSlow中找到它)

HttpContext context = HttpContext.Current;
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
HttpContext.Current.Response.AppendHeader("Content-encoding", "gzip");
HttpContext.Current.Response.Cache.VaryByHeaders["Accept-encoding"] = true;
Run Code Online (Sandbox Code Playgroud)

上面的代码只压缩我的.aspx页面代码(标记)而不是CSS和JS文件,它们作为外部文件包含在内.请告诉我如何使用代码在ASP.NET中实现GZip压缩(因为我在共享主机服务器上,我无法访问IIS服务器配置).而且在上面的代码中,我没有得到最后两行,为什么使用它们以及这些行的目的是什么.请解释!

谢谢

c# compression asp.net gzip

80
推荐指数
4
解决办法
9万
查看次数

GZip压缩在IIS 7.5上无法正常工作

我试图支持IIS下的静态文件的GZip压缩(默认情况下应该启用但不能)但到目前为止还没有工作.这是<system.webServer>Web应用程序的web.config文件中节点下的部分;

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/json" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/x-javascript" enabled="true" />
    <add mimeType="application/atom+xml" enabled="true" />
    <add mimeType="application/xaml+xml" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </staticTypes>
</httpCompression>

<urlCompression doStaticCompression="true" />
Run Code Online (Sandbox Code Playgroud)

我尝试使用谷歌浏览器.这是请求标题;

接受:text/html,application/xhtml + xml,application/xml; q = 0.9,/ ; q = 0.8

接收字符集:ISO-8859-1,utf-8; Q = …

.net asp.net iis gzip iis-7.5

57
推荐指数
4
解决办法
5万
查看次数

Sitecore MVC - gzip 压缩错误

我在使用 Sitecore MVC 3 渲染和 GZip 内容压缩时遇到问题。

我关注了 John West 的博客文章,如何在 Sitecore 中启用 MVC

到目前为止,它运行良好,页面已呈现。但是,如果我在 IIS 上运行该页面并启用内容压缩 (gzip),则该页面不会加载。我在 Firefox 中收到“内容编码错误”。其他浏览器显示各种错误信息。

有人遇到过类似的问题吗?你知道可能是什么问题吗?我应该从哪里开始检查?我必须在页面上使用压缩。

我们正在使用 Sitecore 6,更新 5:“Sitecore 6.6.0 rev. 130404” 这可能是 Sitecore 的错误吗?

编辑 1:我还在 Sitecore 实例上运行 ASP.NET WebForms,它也可以使用 gzip 压缩正常工作。

编辑 2:我启用了“dynamicCompressionBeforeCache”。我的 web.config 与 gzip 配置相关:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
  <dynamicTypes>
    <add mimeType="text/*" enabled="true" />
    <add mimeType="message/*" enabled="true" />
    <add mimeType="application/javascript" enabled="true" />
    <add mimeType="*/*" enabled="false" />
  </dynamicTypes>
  <staticTypes>
    <add mimeType="text/*" enabled="true" …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc gzip sitecore http-compression sitecore6

3
推荐指数
1
解决办法
2745
查看次数

共享主机上的 IIS 7.5 gzip 压缩

我有一个网站,它使用 ASP.NET 并托管在 IIS 7.5 共享主机上,因此我无法直接访问 IIS 设置。现在我想使用 IIS 功能启用我的页面和 css/js 文件的 gzip 压缩,但是在 Internet 上找到的任何方法都不适合我。例如,当我将这里写的内容添加到我的 Web.config 时,没有任何变化:没有错误,没有压缩。

这可能吗?如果没有,最好的选择是什么?

asp.net gzip shared-hosting web-config iis-7.5

2
推荐指数
1
解决办法
5544
查看次数