1. Use Cases
When the page data does not need to be changed frequently, the static page mode can be used.
2. Benefits of using static pages
(1) Improve Website access speed
(2) reduce server burden
(3) Search Engine crawling
3. ASP. NET generate static pages
There are many ways to generate static pages. First, let's talk about one of the methods I use.References
Basic Ideas:
(1)create A template.html file, which defines some special string formats for content replacement, such as $ htmlformat
(2) read the template and assign values to the stringbuilder object.
(3) Replace the special string format with the desired content
(4) Create a New Static Page and write the stringbuilder object to the file.
4. Method
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. Web; Using System. text; Using System. IO; /// <Summary> /// Converthtmlpage: generate a static page /// </Summary> Public Class Converthtmlpage { /// <Summary> /// Generate HTML files /// </Summary> /// <Param name = "templatepath"> Template path </Param> /// <Param name = "templatename"> Template Name </Param> /// <Param name = "htmlpath"> Generate HTML path </Param> /// <Param name = "htmlname"> Generate HTML name </Param> /// <Param name = "format"> Replaced content </Param> /// <Returns> </returns> Public Static Bool Createpage ( String Templatepath, String Templatename, String Htmlpath, String Htmlname, list < String > Format ){ Try { // Read template files Stringbuilder htmltext = New Stringbuilder (); Using (Streamreader sr = New Streamreader (templatepath + Templatename )){ String Line; While (Line = Sr. Readline ())! = Null ) {Htmltext. appendline (line);} Sr. Close ();} // Replace the TAG content in HTML For ( Int I = 0 ; I <format. Count; I ++ ) {Htmltext. Replace ( " $ Htmlformat [ " + I + " ] " , Format [I]);} // Generate HTML files Using (Streamwriter Sw = New Streamwriter (htmlpath + htmlname, False , System. Text. encoding. getencoding ( " Gb2312 " ) {Sw. writeline (htmltext); Sw. Flush (); Sw. Close ();}} Catch (Exception ex ){ Return False ;} Return True ;}}
Download instance
Author: forevernome
Source: http://www.cnblogs.com/ForEvErNoME/
You are welcome to repost or share it, but be sure to declare it
Article Source. If the article is helpful to you, I hope you can
Recommendation Or
Follow