Use response. Filter to generate static pages for simplified and traditional conversion. Use urlrewrite and Asp.net to dynamically generate HTM pages

Source: Internet
Author: User
// Response. the filter is actually a stream type and can be written. therefore, we can perform some processing before the page is finally presented to the client, such as removing invalid characters in the page, simplified and traditional conversion, static page generation, and so on.
See the following Using system;
Using system. Data;
Using system. configuration;
Using system. LINQ;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. xml. LINQ;
Using system. IO;
Using system. text;
/// <Summary>
/// Summary description for responsefilter
/// </Summary>
Public class responsefilter: Stream
{
Stream newstream;
Long position;

Stringbuilder strb = new stringbuilder ();
Public responsefilter ()
{
//
// Todo: Add constructor logic here
//
}
Public responsefilter (Stream inputstream)
{
Newstream = inputstream;
//
// Todo: Add constructor logic here
//
}
Public override bool Canread
{
Get {return true ;}
}

Public override bool canseek
{
Get {return true ;}
}

Public override bool canwrite
{
Get {return true ;}
}

Public override void flush ()
{
Newstream. Flush ();
}

Public override long length
{
Get {return 0 ;}
}

Public override long position
{
Get {return position ;}
Set {position = value ;}
}

Public override int read (byte [] buffer, int offset, int count)
{
Return newstream. Read (buffer, offset, count );
}

Public override long seek (long offset, seekorigin origin)
{
Return newstream. Seek (offset, origin );
}

Public override void setlength (long value)
{
Newstream. setlength (value );
}

Public override void write (byte [] buffer, int offset, int count)
{
// String sbuffer = system. Text. utf8encoding. utf8.getstring (buffer, offset, count );

//// Obtain the list of invalid words, which can be read from the database or web. config.
// String pattern = @ "(Illegal word 1 | illegal word 2 | illegal word 3 )";
// String [] S = pattern. Split (New String [] {"|"}, stringsplitoptions. removeemptyentries );

// Foreach (string S1 in S)
//{
// Sbuffer = sbuffer. Replace (S1 ,"**");
//}

// Byte [] DATA = system. Text. utf8encoding. utf8.getbytes (sbuffer );
// Newstream. Write (data, 0, Data. Length );
//----------------------------------------------------------------
String S = Microsoft. VisualBasic. Strings. strconv (
Encoding. getencoding ("gb2312"). getstring (buffer ),
Microsoft. VisualBasic. vbstrconv. traditionalchinese, 0 );
Byte [] DATA = encoding. getencoding ("big5"). getbytes (s );
Newstream. Write (data, 0, Data. Length );

}
}

// Call the method. Void application_beginrequest (Object sender, eventargs E)
{
// Context. response. charset = "big5 ";
// Context. response. Buffer = false;
Context. response. Filter = new responsefilter (response. Filter );
}

Protected void button#click (Object sender, eventargs E)
{
// Response. Filter = new gzipstream (response. filter, compressionmode. Compress );
// Response. addheader ("content-encoding", "gzip ");
}

// This is suitable for processing multiple pages at a time
Public void application_beginrequest ()
{
String Path = httpcontext. Current. Request. Path. tolower ();
String [] paths = new string []
{
"/AA/", "/BB /"
};
Foreach (string item in paths)
{
If (path. startswith (item ))
{
Response. Filter = new responsefilter (response. Filter );
Break;
}
}
} Or rewrite the render method of a page.

Protected override void render (htmltextwriter writer)
{
Stringwriter strwriter = new stringwriter ();
Base. Render (New htmltextwriter (strwriter ));
String html = strwriter. tostring ();
Html = util. replaceinvalidkeyword (HTML );
Writer. Write (HTML );
}

Use urlrewrite and Asp.net to dynamically generate HTM pages

Http://www.cnblogs.com/fengfeng/archive/2008/02/15/1069462.html

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.