ASP.NET Dynamic Generate HTML Page For: Microsoft ASP.NET
Summary: ASP.NET Dynamically generates HTML page
Introduction:
This feature applies to a Web site that is not strong in the background database, that is, most of the text is not stored in the database, but placed in an HTML file or XML file, just put the index into the database, such as articles title, category, Query keywords, etc.. This is suitable for a web site that does not have database support such as MS SQL Server such as MS SQL Server.
Suitable for news distribution systems, such as Sina, 163, etc., are dynamically generated by HTML pages.
Suitable for programs that require dynamic custom pages. For example, forum, chat room, etc. You can load custom HTML pages to strengthen your appearance.
Think
1. Use tools such as DW-MX to generate a template of the HTML format, add special tags (such as $ HTMLFORMAT $) where you need to add formats, dynamically generate files to read this template when you use the code, then get the contents of the front desk, Add to this template's tag position, generate a new file name After writing a disk, write the related data (directory data) to the database after writing.
2. Use the background code hard to encode the HTML file, you can use the HTMLTextWriter class to write the HTML file.
advantage
1. You can create a very complex page, using methods containing JS files, join the document.write () method in the JS file can be added to all pages, advertising, etc.
2. Static HTML file Use the MS Windows2000 INDEX Server to establish a full-text search engine, using ASP.NET to get search results in a DataTable method. The Win2000's INDEX service cannot find the content of the XML file. This search feature will be very powerful if the database search is included with the INDEX index.
3. Save the server's load, request a static HTML file to save a lot than an ASPX file server resource.
Disadvantage
Idea 2: If you use hard-coded way, the workload is very large, you need a lot of HTML code. Difficulties in debugging. Moreover, the HTML style generated by hardcod cannot be modified. If the site is replaced, then you must re-encode, bringing huge effort to the later period.
Therefore, the first idea is used below, and the code code:
1. Define (Template.htm) HTML Template Page
// -------------------- Read the HTML template page to the StringBuilder object ----
String [] format = new string [4]; // Define an array of HTMLYEM tags
Stringbuilder HTMLText = New StringBuilder ();
Try
{
Using (StreamReader SR = New StreamReader ("Path and Page Name of the Template page")))))
{
String line;
While (line = sr.readline ())! = null)
{
HtmlText.Append (line);
}
sr.close ();
}
}
Catch
{