Asp.net 2.0 is a good way to generate static pages on the home page of a website-qingyueer. Net Wanhua tube Asp.net technology Asp.net tutorial Asp.net source code Asp.net basic ASP. ne

Source: Internet
Author: User

 

Asp.net 2.0 is a good way to generate static pages on the home page of a website-qingyue'er. Net Wanhua tube Asp.net technology Asp.net tutorial Asp.net source code Asp.net basic Asp.net control Asp.net entry-csdnblog

 

 

During website creation, sometimes static pages are generated on the homepage to Improve the Performance (of course, the page cache in Asp.net is also a good choice.
There are many static methods for generating pages, and there are n (n> 1) incomplete statistics)
Haha
The following methods are explained by Mencius E.
The Code is as follows:
Protected override void render (htmltextwriter writer)
...{
System. Io. stringwriter html = new system. Io. stringwriter ();
System. Web. UI. htmltextwriter Tw = new htmltextwriter (HTML );
Base. Render (TW );
System. Io. streamwriter Sw = new system. Io. streamwriter (server. mappath ("index.html"), false, system. Text. encoding. Default );
Sw. Write (html. tostring ());
Sw. Close ();
Tw. Close ();
Response. Write ("page generation successful! ");
}
Add the above function numbers to the page where you want to generate the static space file,
After the function is loaded, the render function captures the HTML text of the page and saves it to a file,
For more information, see the lifecycle of the Asp.net page.
Static Page generation
Protected override void render (htmltextwriter writer ){
Streamwriter r = new streamwriter (server. mappath (staticfilename ),
False, system. Text. encoding. utf8); // staticfilename is the HTML file name.
Htmltextwriter H = new htmltextwriter (R );
Base. Render (h );
R. Close ();
H. Close ();
Response. Redirect (staticfilename );
}
Then, in the pageload event of the same aspx, determine whether the staticfilename already exists. If so, you should turn directly and do not generate the page any more.

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1536753

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.