Compressing all pages by gzip or deflate greatly reduces the volume of page transfers.
You can use Fiddler2 to observe changes in page size after compression.
Add Global.asax to your project, and add the following code:
1 protected void Application_BeginRequest (object sender, EventArgs e)
2 {
3 HttpApplication app = (HttpApplication) sender;
4 string acceptencoding = App. request.headers["Accept-encoding"];
5 Stream Prevuncompressedstream = App. Response.filter;
6 if (acceptencoding = null | | acceptencoding.length = 0) return;
7 acceptencoding = Acceptencoding.tolower ();
8 if (Acceptencoding.contains ("gzip"))
9 {
Ten//gzip
One app. Response.filter = new GZipStream (Prevuncompressedstream, compressionmode.compress);
App. Response.appendheader ("content-encoding", "gzip");
13}
Or else if (acceptencoding.contains ("deflate"))
15 {
//Defalte
App. Response.filter = new Deflatestream (Prevuncompressedstream, compressionmode.compress);
App. Response.appendheader ("content-encoding", "deflate");
19}
20}
Correction:
This method I accidentally found on the internet, I did not use in the actual project, compression effect is there, but on the server side of the resource consumption I have not tested, so it is not too clear this and IIS in the way to set the compression of that good. Temporarily just do a code backup, later with empty in the study.
In addition, there are drawbacks to this method, I found in the experiment that will cause the. NET from the TreeView's small icon failed. The reason is that the TreeView in the use of the default small icon, the picture file is obtained by WebResource.axd, and compression can not get the picture, so at the beginning of the code to filter the requested file, WebResource.axd do not compress.