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