CMS system template engine design (2): Page Production Process

Source: Internet
Author: User
In the previous section, we introduced several basic classes. Next, let's talk about the operating mechanism of the CMS system. When a URL request comes in, our CMS system will analyze the URL to know which site the domain belongs to and which page the URL complies, then, replace the label in the template of the page with the line. How can I intercept URL requests? That is, httpmodule. Customize a cmshttpmodule: ihttpmodule. Add the configuration of httpmodule in config.

I drew a picture and checked the production process first.

The procedure is as follows:

Obtain the site that matches the current domain. If no match is found, the site does not exist in the database. Then only empty information can be output.
[Note] If you want your url to be accessed without a suffix, you must add "wildcard ing" and cannot "check whether a file exists". What is a wildcard? Even if all the URL formats, no matter what is the last and whether there is a suffix, will go through the ISAPI filter of ASP. NET. That is, we define the httpmodule, including static resources such as images and JS on the page. Therefore, we must filter out suffixes that we do not want to process. These suffixes can be configured for each site or global. Therefore, we need to add a Config attribute to the site class, define a Config class.

Code

Public   Class Config
{
Private Idictionary < String , String > _ Configs;

Public   String   This [ String Key]
{
Get
{
Return _ Configs ! =   Null   && _ Configs. containskey (key) ? _ Configs [Key]: String . Empty;
}
Set
{
If (_ Configs =   Null )
{
_ Configs =   New Dictionary < String , String > ();
}

If(_ Configs. containskey (key ))
_ Configs [Key]=Value;
Else
_ Configs. Add (Key, value );
}
}
}

 

The logic for obtaining configvalue from site is to first obtain configvalue from its own config. If it is not obtained from global config. Why is config required? Because different sites may need to customize some variables for use at the foreground.

Okay. After filtering is finished, you should get the page.

The hashtable can also be used to cache the page instance based on the URL, because the request for getting the instance is too large and the complexity also needs to be reduced to O (1 ).

If the page is null, it indicates that the page does not exist in the Database. Therefore, we need to jump out of the httpmodule and let IIS take over and continue processing.

If yes, you need to determine whether the page is cached. Here, the cache actually generates a static page. If yes, generate a static page file name based on the URL and check whether the file exists, if a file exists, determine whether the file creation time expires. If it expires, we have to re-write a new file. by returning the old file, we will overwrite the old file after the new file is created successfully (read/write splitting ).

If it is not cached, the page. template. Content is obtained, labels is cyclically executed, and content is replaced.

VaR html = Page. template. content;
Foreach (VAR label In Page. Labels)
{
Html = Html. Replace (Label. template, label. gethtml ());
}

 

After the HTML of the tag is replaced, the page production is completed.

I am talking about a rough framework. There will be a lot of details in the development process. I will not mention it, but I will only mention some important things. Next, let's talk about how to design the label!

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.