简体   繁体   English

在asp.net中设置gzip压缩

[英]Setting the gzip compression in asp.net

有没有办法在web.config级别设置gzip压缩,还是只能在IIS管理控制台中执行此操作?

Here try this: Sped my site up by about 400% percent. 试试这个:加速我的网站增加约400%。 Worked on first try. 第一次尝试。

Activate GZip with web.config 使用web.config激活GZip

<system.webServer>
  <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"/>
      <add mimeType="message/*" enabled="true"/>
      <add mimeType="application/javascript" enabled="true"/>
      <add mimeType="*/*" enabled="false"/>
    </staticTypes>
  </httpCompression>
  <urlCompression doStaticCompression="true" doDynamicCompression="true"/>
</system.webServer>

Yes you can enable compression with the web.config, as the article below shows- but it can depend on the permissions on the server allows sites. 是的,您可以使用web.config启用压缩,如下面的文章所示 - 但它可以取决于服务器允许站点的权限。

You should note that dynamic compression (anything that needs to be processed before ti can be sent to the client) can increase the load on the server because its having to do compression on every single request. 您应该注意到动态压缩(在ti发送到客户端之前需要处理的任何内容)会增加服务器上的负载,因为它必须对每个请求进行压缩。

IIS7 Compression IIS7压缩


Edit: note this is for IIS7 (as you have tagged) 编辑:注意这是为IIS7(因为你已标记)

It can be complicated or even impossible to modify the applicationHost.config on all environments. 在所有环境中修改applicationHost.config可能很复杂甚至不可能。

So why not simply gzip in code as shown in this post http://laubplusco.net/gzip-svg-files-asp-net/ 那么为什么不简单地在代码中使用gzip,如本文所示http://laubplusco.net/gzip-svg-files-asp-net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM