Technical Principle Analysis [3: Record framework processing process]

Source: Internet
Author: User

To analyze the entire processing process of my records, first go to the wojilu initialization portal to see what wojilu did during initialization.

Related code: wojilu. WebGlobal. asax

 

1 void Application_Start (object sender, EventArgs e ){
2 wojilu. Web. SystemInfo. Init ();
3 wojilu. Web. Mvc. MvcFilterLoader. Init ();
4 wojilu. Web. Jobs. WebJobStarter. Init ();
5}
Wojilu. Web. SystemInfo: the system's fixed data, such as the website root path, app path, host (ip + port number) name, and so on. The information here is the reference information for future routing. The data here will be used in future URL and actual address ing.

Wojilu. Web. Mvc. MvcFilterLoader: The loader of the mvc filter. Initialize various filters and register them to the system.

Wojilu. Web. Jobs. WebJobStarter: Initialize the scheduled task initiator.

WebJob: scheduled tasks. Similar to a service task, you can specify the Interval (Interval ).

Through the above steps, the entire system can respond to the URL request.

 

Next we will introduce the entire MVC process:

 

A standard MVC flow refers to the whole process from Route to page Render.

All the tasks originally completed by ASP are now completed by the wojilu system.

Before introducing each Process in detail, let's take a look at the definition of ProcessorBase:

 

1 namespace wojilu. Web. Mvc. Processors {
2
3 internal abstract class ProcessorBase {
4
5
6 public abstract void Process (ProcessContext context );
7
8}
9
10}
ProcessorBase is an abstract class with an abstract method Process. The parameter of this method is ProcessContext (processing content ). ProcessContext contains all the information required to generate the page. Starting from route parsing, data is enriched from URL information through various processes. For example, when a route is passed, the URL is interpreted as the page Controller information in ProcessContext. When the Process passes security authentication, the access permission and other information will be appended to ProcessContext. ProcessContext is the carrier of information throughout the Process.

After learning about the entire MVC process, let's ask where the initial place that triggers MVC is.

We know that to customize HTTP processing, you must implement an IHttpHandler by yourself. To achieve all the HTTP access processes in the record system, you must implement IHttpHandler. So wojilu's IHttpHandler implementation is the source of the entire MVC.

 

1 /*
2 * Copyright 2010 www.wojilu.com
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License ");
5 * you may not use this file except T in compliance with the License.
6 * You may obtain a copy of the License
7 *
8 *

9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "as is" BASIS,
12 * without warranties or conditions of any kind, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 using System;
18 using System. Web;
19 using System. Web. SessionState;
20
21 using wojilu. Web. Context;
22 using wojilu. Caching;
23 using System. Text;
24 using System. Collections. Generic;
25
26 namespace wojilu. Web. Mvc {
27 /// <summary>
28 // wojilu mvc core processor: Process client requests and return the results
29 /// </summary>
30 public class CoreHandler: IHttpHandler, IRequiresSessionState {
31 public virtual void ProcessRequest (HttpContext context ){
32 if (MvcConfig. Instance. IsPageCache ){
33 String pageContent = CacheManager. GetApplicationCache (). Get (context. Request. Url. PathAndQuery) as String;
34 if (pageContent! = Null ){
35 context. Response. Write (pageContent );
36 return;
37}
38}
39 MvcContext ctx = new MvcContext (new WebContext (context ));
40 ProcessContext. Begin (ctx );
41}
42 public virtual void ProcessRequest (IWebContext context ){
43 ProcessContext. Begin (new MvcContext (context ));
44}
45 public Boolean IsReusable {
46 get {return true ;}
47}
48}
49}
How does the system know which IHttpHandler is used for HTTP?

Next, open the Web. Config file of the source code wojilu. Web.

Here is an httpHandlers section:

It defines the processing methods for various requests. For example, for refresh.aspx, wojilu.web.handler.refreshserverhandleris used for processing. robots.txt uses System. Web. DefaultHttpHandler for processing.

In the last line, if the request does not belong to the responsibility of other processing methods (such as aspx), wojilu. Web. Mvc. CoreHandler will be used for processing.

1 2 <add verb = "*" path = "CaptchaImage. ashx" type = "wojilu. Web. Handler. CaptchaImageHandler, wojilu"/>
3 <! -- <Add verb = "*" path = "WebForm1.aspx" type = "System. Web. UI. PageHandlerFactory"/> -->
4 <add verb = "*" path = "*. asp" type = "wojilu. Web. Handler. PageNotFoundHandler, wojilu"/>
5 <add verb = "*" path = "robots.txt" type = "System. Web. DefaultHttpHandler"/>
6 <add verb = "*" path = "refresh. aspx" type = "wojilu. Web. Handler. RefreshServerHandler, wojilu. Core"/>
7 <add verb = "*" path = "*. css ,*. jpg ,*. jpeg ,*. gif ,*. png ,*. bmp ,*. ico ,*. js ,*. htm ,*. html ,*. xml ,*. swf ,*. zip ,*. 7z ,*. rar ,*. cur "type =" System. web. defaultHttpHandler "/>
8 <add verb = "*" path = "*" type = "wojilu. Web. Mvc. CoreHandler, wojilu"/>
9 In this case, for the aspx page request, you can view the Config to know that wojilu. Web. Mvc. CoreHandler is used for processing. Call the ProcessRequest method of wojilu. Web. Mvc. CoreHandler to start processing the request. ProcessContext. Begin of ProcessRequest officially started the MVC journey.

Config->

Wojilu. Web. Mvc. CoreHandler. ProcessRequest->

Wojilu. Web. Mvc. CoreHandler. ProcessRequest: ProcessContext. Begin

Here we will introduce the general process of the entire MVC and the entry method to the MVC. You can learn how to use wojilu as the entry here.

 

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.