Analysis of QBlog technical principles in the autumn color Park: Module-based page design (V)

Source: Internet
Author: User

Review:

1. Analysis of QBlog technology principles in the autumn Garden: Opening part: Overall understanding (1) -- introduces the role of the overall folder and file

2: Analysis of QBlog technical principles of the autumn color Garden: Understanding the whole site processing process (2)-introducing the business processing process of the autumn color Garden

3: Analysis of QBlog technical principles in the autumn color Park: UrlRewrite's principle of URL without a suffix (3) -- introduces how to implement URL without a suffix

4: Analysis of QBlog technical principles in the autumn Garden: URL redirection System of UrlRewrite (4) -- introduce how to locate the processing program in the URL

Ps: QBlog: Http://www.cyqdata.com/download/article-detail-427

 

This section describes how to design a base class for a page and parse the base class design scheme of QBlog in the autumn garden.

 

1. Traditional WebForm Page Base Class

 

The traditional Page base class basically inherits from System. Web. UI. Page, for example:

///
/// Share the Page Base Class
///

Public class PageBase: System. Web. UI. Page
{}

Why is this inheritance?

1: It is required to deal with some common logic, reduce code, and unify some things.

2: in development, many user controls and ViewState are used to enjoy the development advantages of rich server controls and improve development efficiency.

3: I am used to WebForm development. Although MVC is popular recently.

I often use it on some internal systems or site management backend, such as using it to handle the following content:

1: User Permissions

2: encapsulate common methods, including server methods and script methods.

3: further control of the list control Repeater/DataList/GridView: for example, the beam effect [is the highlighted display of rows when moving], column header translation, and column hiding control.

4: Other ......

Let's take a brief look at System. Web. UI. Page and find the following inheritance:

Public class Page: TemplateControl, IHttpHandler
{
// Summary:
// A string that defines the hidden fields of eventargument in the rendered page.
[EditorBrowsable (1)]
Public const string postEventArgumentID = "_ EVENTARGUMENT ";
//
// Summary:
// A string that defines the hidden fields of eventtarget in the rendered page.
[EditorBrowsable (1)]
Public const string postEventSourceID = "_ EVENTTARGET ";

// Summary:
// Initialize a new instance of the System. Web. UI. Page class.
Public Page ();

// Omit N rows...

}

In short:

In order to deal with a variety of server-side controls, it inherits the TemplateControl, a rich control base class, And the ViewState introduced at the same time. At the same time, it was also despised by the world, and even pushed the reasons for slow website operation to ViewState.

 

Conservative estimation may be due to some groups of people. The reason for using mvc is that mvc does not have viewstate, And it is generated with clean html.

For example:

Many people see the QBlog site of the autumn garden. When they click to view the html source code and cannot find the ViewState shadow in the html,

Ask about power generation:

Is the autumn garden developed by mvc?

Ah ~ Is mvc without ViewState?

If there is no ViewState, it is not necessarily mvc. It may be handled as you do:

1: truncates the output before the output, replaces the html, and then outputs the clean html

2: Use the 1 method to save the output html as a file

3: The request can cache html or directly request html

 

Why does the generated html have no ViewState and the ViewState is replaced before the output? Answer: No.

 

Ii. Design of the foundation of the autumn Garden

 

The basic class design of the autumn garden is just a step back. Like System. Web. UI. Page, It inherits from: IHttpHandler.

For example:

Public abstract class HttpCustom: IHttpHandler
{}

 

The following content:

The example of redirecting the URL in section 3 to Default. aspx will be further supplemented to explain the design of the base class of the autumn garden for everyone:

 

1: create a new class library. For your convenience, the class name also starts with UrlRewrite and is called UrlRewriteModule.

 

2: Rename Class1.cs to HttpCustom and inherit from IHttpHandler, for example:

As you can see, the class writes less keywords: abstract, haha ~

 

3: Create your own page lifecycle method, which is roughly as follows:

Note:

In the above example, we have created a Page life cycle of our own, and the Page life cycle of the Page that often belongs to the interview questions is still at one side.

 

4: Next, let's do something, introduce the focus to the ashx processing program, and discard aspx.

 

4.1: Add a reference to the UrlRewriteModule of the project in the original site UrlRewriteDemo.

4.2: add the Default. ashx handler, inherit from HttpCustom, and override the Page_Load method:

4.3: relocate the UrlRewrite database from the previous location to Defaut. aspx to Default. ashx.

 

5: Everything is ready. Run F5 to check the effect.

Next:

After the above tossing:

We have implemented our own page lifecycle and assigned them to various ashx handlers using the familiar Page_Load method. Of course, there are still many things to be done by the base class, A lot of methods are private, which means you have to handle them yourself. This is to be continued later.

 

Summary:

This section ends here. From this section, we can see that in the design of the QBlog (http://www.cyqdata.com/), the traditional Page and all its user controls are abandoned, has created its own life cycle.

However, when Asp.net does not have aspx or ascx, how does the autumn garden create a new development process? How to load and present pages? How to trigger event requests?

The next section will be parsed for you. Stay tuned.

 

Finally, download the example in this section: UrlRewriteModule.rar

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.