asp.net dynamically generate HTML pages (template technology)
Source: Internet
Author: User
Brief introduction
This feature is suitable for Web sites with weak background database functions, that is, most of the text is not stored in the records of the database, but in the HTML file or XML file, just put the index into the database, such as the title of the article, category, query keywords and so on. This is appropriate for Web sites in the background that do not have database support such as MS SQL Server.
Apply to the news release system, such as Sina, 163, etc. are dynamically generated HTML page.
Applies to programs that need to dynamically customize the page. such as forums, chat rooms and so on. You can load custom HTML pages to enhance your appearance.
train of Thought
1. Use tools such as DW-MX to generate HTML-formatted templates, add special tags (such as $htmlformat$) where needed, and dynamically generate files using code to read the template, and then get the foreground input to add to the tag location of the template, Writes the new file name to the disk and writes the relevant data to the database after it is written.
2. Using background code to hard-code HTML files, you can use the HtmlTextWriter class to write HTML files.
Advantages
1. Can be a very complex page, using the method containing JS files, in the JS file to add document.write () method can be added to all pages, such as page header, advertising and other content.
2. Static HTML files Use MS Windows2000 's Index server to create Full-text search engines, using asp.net to get search results in a DataTable. The Win2000 Index Service was unable to find the contents of the XML file. If you include a database search and index index double lookup, then this search function will be very powerful.
3. Save the load on the server and request a static HTML file to save a lot more than an ASPX file server resource.
Disadvantage
Idea two: If the hard coded way, the workload is very large, need a lot of HTML code. Debugging difficult. And the HTML style generated with hard coding cannot be modified, and if the site is replaced, it must be coded to bring a huge workload to the later stage.
----------generate an HTM file------------------??
Try
{
Using (StreamWriter Sw=new StreamWriter ("Store path and page name", False,system.text.encoding.getencoding ("GB2312"))
{
Sw. WriteLine (HTMLText);
Sw. Flush ();
Sw. Close ();
}
}
Catch
{
Response.Write ("The file could not be wirte:");
}
Summary
This method makes it easy to generate HTML files. The program uses a circular replacement, so the template that needs to replace a large number of elements is fast.
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.