This function is applicable to websites with poor background database functions, that is, most of the text is not stored in the database records, but in html or xml files, and only the index is placed in the database, such as the title, category, and keyword of an article. this method is suitable for websites without database support such as MS SQL Server in the background.
Applicable to news publishing systems, such as sina and 163, which dynamically generate html pages.
It is applicable to programs that require dynamic page customization, such as forums and chat rooms. Custom html pages can be loaded to enhance the appearance.
Ideas
1. use a tool such as Dw-Mx to generate an html template, and add special tags (such as $ htmlformat $) where the format needs to be added. When a file is dynamically generated, use the code to read the template, obtain the content entered at the front end, add it to the tag location of this template, generate a new file name, and write it to the disk. Then, write the data to the database.
2. Html files are hardcoded Using Background code. You can use the HtmlTextWriter class to write html files.
Advantages
1. you can create complex pages and add document to the js file by using methods that contain js files. the write () method can be used to add content such as the page header and advertisement to all pages.
2. static html files use Index Server of MS Windows2000 to create a full-text search engine, and asp.net to obtain search results in DataTable mode. the Index Service of Win2000 cannot find the content of the xml file. if both database search and Index search are included, this search function is very powerful.
3. Saving server load and saving a lot of resources by requesting a static html file than An aspx file server.
Disadvantages
Train of Thought 2: If hard encoding is used, the workload is very heavy and requires a lot of html code. debugging is difficult. in addition, html styles generated by hard encoding cannot be modified. If the website style is changed, it must be re-encoded, which will bring a huge workload in the future.
Therefore, the first approach is adopted here.
Column code
1. Define (template.htm) html template page
<Html> // ---- Read the html template page
In the stringbuilder object, ---- string [] format = new string [4];
// Define an array with the same number of htmlyem tags
Stringbuilder htmltext = new stringbuilder ();
Try
{
Using (streamreader sr = new streamreader ("path for storing template pages and Page name "))
{
String line;
While (line = Sr. Readline ())! = NULL)
{
Htmltext. append (line );
}
Sr. Close ();
}
}
Catch
{
Response. Write ("<SCRIPT> alert () </SCRIPT> ");
}
// ---------- Assign a value to the tag array ----------- format [0] = "background =" bg.jpg ""; // format of the background image [1] = "#990099 "; // font color format [2] = "150px"; // font size format [3] = "<marquee> generated template html page </marquee> "; // text description // ---------- Replace the content marked in the htm for (int I = 0; I <4; I ++) {htmltext. replace ("$ htmlformat [" + I + "]", format [I]);
}
// ---------- Generate the htm file ------------------――
Try
{
Using (StreamWriter sw = new StreamWrite * ("Storage path and Page name", ** lse, System. Text. Encoding. GetEncoding ("GB2312 ")))
{
Sw. WriteLine (htmltext );
Sw. Flush ();
Sw. Close ();
}
}
Catch
{
Response. Write ("The file cocould not be wirte :");
}
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