Asp.net output overwrites the compressed page file instance code

Source: Internet
Author: User

Example
Copy codeThe Code is 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.html Controls;
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

1. WebResourceCompression compression module

This compression module is used to compress ASP in real time. all *. axd resources. Generally, when the aspx page uses ajax frameworks such as anthem.net or the asp.net verification control, axd file references are generated. This file is actually a js script. After this compression module is enabled, all axd resources are compressed by GZIP and then sent to the client. This module is especially suitable for projects where the aspx page applies the ajax framework or the large axd resource file needs to be referenced!

Use: Decompress the package and place WebResourceCompression. dll to the BIN directory of the website project. In the Web. config The Code is as follows:
Copy codeThe Code is as follows:
<Add name = "WebResourceCompression" type = "WebResourceCompression. WebResourceCompressionModule"/>

Advantage: easy to use
Disadvantage: Only ASP. NET2.0 or later versions are supported. Other resources except axd cannot be compressed!

Ii. PageCompression compression module


Unlike previous modules, this module is used to compress the aspx page. After this compression module is enabled, the aspx page will be compressed in real time, generally, KB of pages can be compressed to about 25 KB. This module is applicable to projects that only need to compress pages!

Use: Decompress Compression. PageCompressionModule. dll to the BIN directory of the website project, and add the following statement to the Web. config The Code is as follows:
Copy codeThe Code is as follows:
<Add name = "PageCompressionModule" type = "Compression. PageCompressionModule, Compression. PageCompressionModule"/>

Advantage: easy to use
Disadvantage: Only ASP. NET2.0 or later versions are supported. Other resources except the aspx page cannot be compressed. After compression is enabled, the axd resources referenced on the page will be invalid (BUG )!

Iii. HttpCompress6.0 compression module


This is an asp. net1.0/1.1/2.0 (versions earlier than 2.0 do not support gzip compression, only deflate compression), can compress all types of resources requested by the aspx page (MimeTypes, including images, js scripts, axd, aspx pages, and css files. in config, you can customize the types of resources to be compressed, the types of resources not compressed, or the specified pages to be compressed or not compressed, there are also powerful custom functions such as setting the compression ratio (high | normal | low). However, the most serious problem with this control is in asp. enabling compression in net2.0 will invalidate the axd file, so that if the ajax framework is applied on the page, the ajax function will become invalid.

Usage: omitted (similar to the CompressionModule compression module recommended below)
Advantages: open source code, powerful custom functions, support for asp. net1.0/1.1/2.0, can compress a variety of resources!
Disadvantage: complicated use. Enabling compression under asp. net2.0 will invalidate the axd file!

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.