One method to build a high performance website

Introduction. 1

How to build a high performance website. 1

Create Article Entity Class. 1

Create Data Access class. 4

Create File Operate Class. 6

Create static article web page class. 8

Reference. 11

 

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#

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值