IIS aspnet HTTP 压缩 与Ajax

最近在做IIS ASPNET的项目,对首页访问速度要求比较高。

通过配置AppPool可以有效提高IIS的响应速度。

启用IIS的HTTP压缩后,对于ASPX的程序处理和Ajax方式调用产生了问题。

IIS的HTTP压缩配置比较简单不能支持比较灵获得配置。

我搜 找到了 blowery.Web.HttpCompress(在线文档) 这个在性能上评价还不错。

配置

Web.config

<configSections>

<sectionGroup name="blowery.web">

<section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>

</sectionGroup>

</configSections>

blowery.web

<blowery.web>

<httpCompress preferredAlgorithm="gzip" compressionLevel="high">

<excludedMimeTypes>

<add type="image/jpeg"/>

<add type="image/gif"/>

<add type="text/plain"/> <!--解决Ajax回调不支持压缩格式的问题-->

</excludedMimeTypes>

<excludedPaths>

<add path="NoCompress.aspx"/>

</excludedPaths>

</httpCompress>

</blowery.web>

excludedMimeTypes 包含的在此的Mime类型将不被压缩

excludedPaths 包含的在此的aspx将不被压缩

注意源代码中有一处bug,在处理excludePaths时不起作用

string realPath = "";

try

{

logger.Debug(app.Request.ApplicationPath);

realPath = app.Request.Path.Remove(0, app.Request.ApplicationPath.Length);

}

catch (Exception ex)

{

logger.Debug(ex.Message);

realPath = "/";

}

经测试 一个35K的页面,可以控制在10~15k大小,这会大大加快传输的速度。

总体效果不错。