How to build a high performance website
Create static article web page class
Introduction
In the modern times, there are a large number of websites on the internet, including static websites and dynamic websites. As we all know, the static websites have higher performance than the dynamic websites, but the static websites’ less communication with customs than dynamic websites. And the question is how can we build a high performance website?
How to build a high performance website
There are many methods to build a high performance website, such as use cache, high performance program, show your information by static pages and manage your website by dynamic pages. And this article just talks about the third method that how to create a high performance website.
Create Article Entity Class
First of all, let’s create a class that used to store article information, the following code shows the ArtilceEntity class and it inherits from IDisposable interface, and this class can use “using” statement to build a code block and it can automatic dispose the resource.
Create Data Access class
This is a class that used to access database, such as create a connection object, and get data table method and ExecuteScalar method. The third method can access database, you can obtain data from database by this method. The following code is the Data Access class.
Create File Operate Class
This is a class that used to read the template file and write a static html file to virtual catalog. And this is a class just to use the IO namespace classes to read and write file. From the following code, there is a line of code “StreamReader sr = new StreamReader(path + FileName + ".template", System.Text.Encoding.GetEncoding("gb2312"));”, and this code used to read the template file, the template file is a file that contains html markup and some special markup like “[$$$title$$$]”, and this markup can be replaced by the article entity property at user click create button.
Create static article web page class
This class inherits from IDisposable interface, it has a Add () method, this method is used to replace the special markup like “[$$$title$$$]” in the template file, and this method calls a static method in File Operate class like
“FileOperate.AddStaticWeb(sb, articleID.ToString());”, to excute this method, we can create a static html file named by artile ID in the determining path. The following code shows how to create a static artile web pages.
From the above code, we can see there is a code block like
And this block is important to this system. In this block, it is using the Replace(string,string) method of the StringBulider class, use this method we can replace the special markup that we defined in the template file, and then we call the AddStaticWeb(string, string) method of the File Operate class to convert StringBuilder object to a string by ToString() method, and then write this string to a html file name by article ID, and then we could create a static html file successful.
Example:
The following code shows how to call all above class method to create a html pages.
Reference
<!--[if !supportLists]-->1、 <!--[endif]-->Microsoft .NET Framework 2.0 Documentation.
<!--[if !supportLists]-->2、 <!--[endif]-->Effective C#