使用Gzip压缩Asp.net 4.5页

时间:2013-12-31 10:48:46

标签: c# asp.net webforms gzip

我正在使用asp.net webform 4.5.1。我想用Gzip方法压缩页面。在添加Gzip的Dll之后在asp.net 2中我将此代码添加到Web.config:

<?xml version="1.0"?>
<configuration>
<configSections>
    <sectionGroup name="DCWeb">
        <section name="HttpCompress" type="DC.Web.HttpCompress.Configuration,            DC.Web.HttpCompress"/>
    </sectionGroup>
</configSections>
<DCWeb>
    <HttpCompress compressionType="GZip">
        <IncludedMimeTypes>
            <add mime="text/html"/>
        </IncludedMimeTypes>
        <ExcludedMimeTypes>
            <add mime="image/jpeg"/>
            <add mime="text/javascript"/>
        </ExcludedMimeTypes>
        <ExcludedPaths>
            <!--<add path="~/Default.aspx" />-->
        </ExcludedPaths>
    </HttpCompress>
</DCWeb>
<appSettings>
    <add key="Anthem.ResponseType" value="application/x-anthem"/>
</appSettings>
<system.web>
    <httpModules>
        <add name="HttpCompressModule" type="DC.Web.HttpCompress.HttpModule,DC.Web.HttpCompress"/>
    </httpModules>
    <httpHandlers>
        <add verb="*" path="js.axd,css.axd" type="DC.Web.HttpCompress.CompressionHandler,DC.Web.HttpCompress"/>
    </httpHandlers>

</system.web>

</configuration>

但是知道我不知道如何在asp.net 4.5.1中这样做。请帮我。 另外我想知道,还有其他更好的方法来压缩网页并加快页面加载吗?

1 个答案:

答案 0 :(得分:0)

新iis需要新配置。处理程序和模块未在<system.webServer>

中定义

我希望这样做:

<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <handlers>
    <add name="HttpCompressHandler" verb="*" path="js.axd,css.axd" type="DC.Web.HttpCompress.CompressionHandler,DC.Web.HttpCompress"/>
  </handlers>
  <modules>
    <add name="HttpCompressModule" type="DC.Web.HttpCompress.HttpModule,DC.Web.HttpCompress"/>
  </modules>
</system.webServer>