I used to use HttpModule to change cookies before Response. Today I encountered Asp.net taking the initiative and converting the Chinese characters ꪻ that I worked so hard to convert into Chinese characters, not to mention Asp.net's Web controls. Even the Html control Ranat=server will be forcibly converted into Chinese characters for output.
If you write out the page content line by line using Response, it would be too tiring and error-prone. So the best way is to perform another conversion after Asp.net's generation action is completed, so that Asp.net has nothing to do with you.
All generation actions of Asp.net are completed in the Render method, so we will perform operations on the Render method:
protected override void Render(HtmlTextWriter writer)
{
StringWriter sw = new StringWriter();
HtmlTextWriter htmlw = new HtmlTextWriter(sw);
//Take out the generated content of the page
base.Render(htmlw);
htmlw.Flush();
htmlw.Close();
string pageContent = sw.ToString();
//Modify the content
pageContent = KillTheBugAndShit(pageContent);
Response.Write(pageContent);
//base.Render (writer);
}
Using this method, you can also take out the content generated by the page and generate a static page for use.
(I think I wrote a post with this content last year...I don’t remember)