HttpCompressionModule (HTTP compression for ASP.NET)
An IHttpModule for ASP.NET that provides compression of HTTP Responses。
开源项目:http://code.google.com/p/httpcompress/
本地下载:httpCompress
使用指南
- Download and install the HttpModule from http://www.blowery.org/. Simply follow this link and download the binary package.
If for some reason you can't download it from Blowery.org try here - Extract the package and copy the extracted files into the bin folder of your .Net application.
blowery.Web.HttpCompress.dll
blowery.Web.HttpCompress.dll.xml
ICSharpCode.SharpZipLib.dll
ICSharpCode.SharpZipLib.dll.xml - Modify your Web.config
-
- Add to the configSections
<sectionGroup name="blowery.web">
<section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>
</sectionGroup> - Add to the httpModules section inside system.web (if httpModules section does not exist, create it)
<httpModules>
<add name="CompressionModule" type="blowery.Web.HttpCompress.HttpModule, blowery.web.HttpCompress"/>
</httpModules> - Add to the configuration section
<blowery.web>
<httpCompress preferredAlgorithm="deflate" compressionLevel="high">
<excludedMimeTypes>
<add type="image/jpeg"/>
<add type="image/gif"/>
</excludedMimeTypes>
<excludedPaths></excludedPaths>
</httpCompress>
</blowery.web>
- Add to the configSections
- That's it!
For more information or troubleshooting please refer to http://www.blowery.org/
转自:http://capitalhead.com/articles/enable-http-compression-for-your-aspnet-applications.aspx
http://www.codeproject.com/KB/aspnet/httpcompression.aspx
中文参考:http://space.itpub.net/7383074/viewspace-469865
HTTP Compression with HttpCompress
By Praveen K Prasad May 02, 2006
This article describes how to enable HTTP compression for ASP.net web applications without having direct access to the server and by using an HttpModule.Introduction
This article is all about how to integrate HTTP compression to your ASP.net web
Http compression is actually a performance optimization technique as documented in the HTTP1.1 protocol standard. It simply means that the Web
The HttpCompress module is actually an httpmodule that can be plugged into your web
How to achieve it
The module we're going to use comes as two dll files
- blowery.Web.HttpCompress.dll
- ICSharpCode.SharpZipLib.dll
After obtaining the files, please follow the steps below
- Place the files inside the 'bin' folder of your application.
- Open the application's configuration file, "web.config" and add the following entries to it.
- Locate the tag <configuration> , it is there in the starting you needn't require to search it out. Just below it add the segment.
<configSections>
<sectionGroup name="blowery.web">
<section name="httpCompress" type="blowery.Web.HttpCompress.SectionHandler, blowery.Web.HttpCompress"/>
</sectionGroup>
</configSections>
<blowery.web>
<httpCompress preferredAlgorithm="gzip" compressionLevel="high">
<excludedMimeTypes>
<add type="image/jpeg"/>
<add type="image/png"/>
<add type="image/gif"/>
</excludedMimeTypes>
<excludedPaths>
<add path="NoCompress.aspx"/>
</excludedPaths>
</httpCompress>
</blowery.web>
This describes a new configSection named <blowery.web> and later this <blowery.web> section is configured. It contains a subsection <httpCompress> thet have to major attributes named, preferredAlgorithm and compressionLevel . preferredAlgorithm specifies which compression algorith is to be used and supported values are gzip/deflate/default. The compressionLevel attribute specifies the amount of comression and the possible values are high/normal/low
The next section is excludedMimeTypes that specifies which MIME types are to be excluded from compression(You'll not benefit from compressing a jpg/gif image which is already compressed). You may add as many number of MIME types and they will not b compressed by HttpCompress while serving
Then comes the excludedPaths section that allows you to exclude a specific path from being compressed.The example segment shows a page Nocompress.aspx being excluded. - Plug-in the module into your application by adding the following lines just below the <system.web> section or anywhere inside it.
<httpModules>
<add name="CompressionModule" type="blowery.Web.HttpCompress.HttpModule, blowery.web.HttpCompress"/>
</httpModules>
This registers the http module with the application instance and it works as a filter for response to the client without directly sending the response to the client, HttpCompress compresses it and sends to the client.
NB:Its not necessary to use compression with your app by using an http module, if the hosted server already performs compression. Client browsers need to support compression for this to work as specified by "Accept-Encoding" in their request.