Asp.net performs operations on the page content after all the page content is generated and before the output content

Source: Internet
Author: User

I used to say that I used httpmodule to change the cookie before response. Today I met Asp.net's self-made claim to convert the representation of the hard-converted Chinese character into Chinese characters, not the Web Control of Asp.net, that is, the HTML control ranat = server will be forcibly converted into Chinese characters for output.
If you write a line of the page content in response, it is too tired and error-prone. So the best way is to perform another conversion after the Asp.net generation is complete, so Asp.net won't be able to take you.
All Asp.net generation actions are completed in the render method, so we will perform the operation on the render method:

Protected override void render (htmltextwriter writer)
{

Stringwriter Sw = new stringwriter ();
Htmltextwriter htmlw = new htmltextwriter (SW );
// Extract the page generated content
Base. Render (htmlw );
Htmlw. Flush ();
Htmlw. Close ();
String pagecontent = Sw. tostring ();
// Modify the content
Pagecontent = killthebugandshit (pagecontent );

Response. Write (pagecontent );

// Base. Render (writer );
}
In this way, you can also take out the content generated by the page to generate a static page.

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.