asp.net output rewrite compressed page File instance Code _ Practical Tips

Source: Internet
Author: User

Example

Copy Code code as follows:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.htmlControls;
Using System.Text.RegularExpressions;
Using System.IO;
<summary>
Pagebase page base class
</summary>
public class PageBase:System.Web.UI.Page
{
protected override void Render (HtmlTextWriter writer)
{
StringWriter SW = new StringWriter ();
HtmlTextWriter htmlwriter = new HtmlTextWriter (SW);
Base. Render (HTMLWriter);
string html = sw. ToString ();
HTML = regex.replace (HTML, "[F v]", "");
HTML = regex.replace (HTML, "{2,}", "");
HTML = regex.replace (HTML, ">[]{1}", ">");
Writer. Write (HTML);
}
}

Add several. NET compression modules

One, webresourcecompression compression module

This compression module is designed for real-time compression of all *.axd resources referenced by asp.net2.0 pages, and the general ASPX page uses an AJAX framework such as Anthem.net or asp.net validation control will produce Axd file references, this file is actually a JS script, enabling this compression module, all the Axd resources will be gzip compressed and then transmitted to the client, this module is particularly suitable for the ASPX page application of the AJAX framework or a large volume of axd resource files to refer to the project !

Use: After decompression, place the WebResourceCompression.dll in the bin directory of the Web site project, and add the following statement to the Web.config The code is as follows:

Copy Code code as follows:

<add name= "webresourcecompression" type= "Webresourcecompression.webresourcecompressionmodule"/>

Advantages: Easy to use
Disadvantage: Only support asp.net2.0 or above version, can not compress other resources except Axd!

Second, pagecompression compression module


Unlike the previous module, this module is designed to compress ASPX pages, after enabling this compression module, the ASPX page will be compressed in real time, the general 100K pages can be compressed to about 25K, this module is suitable for the page only to compress the project!

Use: After decompression, place the Compression.PageCompressionModule.dll in the bin directory of the Web site project, and add the following statement to the Web.config The code is as follows:

Copy Code code as follows:

<add name= "Pagecompressionmodule" type= "Compression.pagecompressionmodule,compression.pagecompressionmodule"/ >

Advantages: Easy to use
Disadvantage: Supports only asp.net2.0 or above, cannot compress other resources except ASPX page, and when compression is enabled, the Axd resources that the page references will not be valid (bugs)!

Three, HttpCompress6.0 compression module


This is a support asp.net1.0/1.1/2.0 (2.0 version does not support gzip compression, only supports deflate compression), can compress all types of ASPX page requests (mimetypes) resources, including pictures, JS scripts, Axd, ASPX pages, CSS files and so on, and can be web.config in detail to compress that type of resources and not compress that type of resources, you can also define to compress the specified page or do not compress the specified page, in addition to the compression ratio set (High|normal|low) and so powerful custom features, However, the most serious problem with this control is that enabling compression under asp.net2.0 causes the Axd file to become invalid, so that AJAX functionality is invalidated if the page applies an AJAX framework.

Use: Slightly (similar to the Compressionmodule compression modules recommended below)
Advantages: Open source code, powerful custom function, support asp.net1.0/1.1/2.0 version, can compress a variety of resources!
Disadvantage: The use of complex, asp.net2.0 to enable compression will cause Axd file invalid!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.