ASP. net mvc-Request Process

Source: Internet
Author: User

ASP. net mvc-Request Process

Request Process Description

For the request process, the article focuses on the relationship between HttpApplication and HttpModule, and a simple example implementation. (HttpModule is the entry point of the MVC Framework)

Figure 1

After the request arrives at the Web server, it enters ASP. NET is implemented through ASP. NET to construct an HttpWorkerRequest object. HttpWorkerRequest is an abstract class, indicating the information processed by some requests. in NET, the HttpRuntime type is used to call the static function ProcessRequest (). The parameter type is HttpWorkerRequest. Because HttpWorkerRequest is abstract, there should be an implementation class in the system. The HttpApplication object is generated within the ProcessRequest () method. In this process, the HttpWorkerPequest object has been processed and converted to the HttpRequest object, the HttpRequest object is publicly accessible by code (not shown in the figure ). At this time, the HttpHandler program is not executed, but the content in HttpModule is first executed, they subscribe to events in HttpApplication for custom modifications between various statuses of the request (these are described in the following example. Then execute HttpHandler. After the processing program is executed, it does not go to HttpResponse, but some custom operations after the request is completed in HttpModule. This is agreed in HttpApplication, the Response operation is performed only when all of these operations are completed.

In the following example, we simulate the event usage model in the HttpApplication type.

Example

Code 1-1

1 public delegate void PassNotice (NoticeContext noticeContext); 2 3 public class Order 4 {5 private NoticeContext _ noticeContext; 6 7 public NoticeContext 8 {9 get {return _ noticeContext ;} 10 set {_ noticeContext = value;} 11} 12 13 private PassNotice _ befPassNotice; 14 public event PassNotice BefPassNotice15 {16 add17 {18 _ befPassNotice + = value; 19} 20 remove21 {22 _ befPassNotice- = Value; 23} 24} 25 26 private PassNotice _ latPassNotice; 27 28 public event PassNotice LatPassNotice29 {30 add31 {32 _ latPassNotice + = value; 33} 34 remove35 {36 _ latPassNotice-= value; 37} 38} 39 40 private void SendGoods () 41 {42 Console. writeLine ("shipping ...... Please wait for receiving "); 43} 44 45 public void Start () 46 {47 if (_ befPassNotice! = Null) 48 {49 _ befPassNotice (NoticeContext); 50} 51 52 if (NoticeContext. isSend) 53 {54 Console. writeLine ("server: the client has been confirmed to be able to ship"); 55 SendGoods (); 56 if (_ latPassNotice! = Null) 57 {58 _ latPassNotice (NoticeContext); 59} 60 if (NoticeContext. isAccept) 61 {62 Console. writeLine ("server: client received"); 63} 64} 65 else66 {67 Console. writeLine ("server: Waiting for client confirmation"); 68} 69 70} 71}View Code

The Order class represents the Order (this is a bit inappropriate here), which contains two PassNotice delegate-type events BefPassNotice, LatPassNotice, verify the order before shipment and actions that can be performed by the customer after shipment (corresponding to various events in HttpApplication ).

Code 1-2

1 public class NoticeContext 2 {3 public bool IsSend {get; set;} 4 public bool IsAccept {get; set ;} 5} 6 7 public class Customer 8 {9 private Order _ Order; 10 public Customer (Order order) 11 {12 _ Order = order; 13 _ Order. befPassNotice + = new PassNotice (_ Order_BefPassNotice); 14 _ Order. latPassNotice + = new PassNotice (_ Order_LatPassNotice); 15} 16 17 void _ Order_LatPassNotice (NoticeContext noticeContext) 18 {19 noticeContext. isAccept = true; 20 Console. writeLine ("client: receiving goods"); 21} 22 23 void _ Order_BefPassNotice (NoticeContext noticeContext) 24 {25 26 noticeContext. isSend = true; 27 Console. writeLine ("client: Shipping allowed"); 28} 29}View Code

Here, the Customer class references the Order class and subscribes to the Order class event to process the NoticeContex type value (similar to HttpModule) in the Order class ).

Call
Code 1-3

1             Order order = new Order();2             Customer customer = new Customer(order);3             order.NoticeContext = new NoticeContext() { IsAccept = false, IsSend = false };4             order.Start();

Result 2:
Figure 2


In this example, there are still many parts that are not described in detail. We only demonstrate a rough model, and we also want to say that the Order type corresponds to a single process (which is inappropriate in this example ), just like HttpApplication can only correspond to one request, the current context information only stores the information of the current request.
In code 1-3, the Customer is called directly, but not in ASP. NET.

The next article will talk about the routing section in MVC. Let's take a look at the previous series.

 

 

Author: Jin Yuan

Source: http://www.cnblogs.com/jin-yuan/

The copyright of this article is shared by the author and the blog Park. You are welcome to reprint this article. However, you must keep this statement without the author's consent and go to the Article Page.

Related Article

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.