The request flow of ASP. NET MVC Preschool

Source: Internet
Author: User

The request flow of ASP. NET MVC Preschool

Request Process Description

For the requested process, the article focuses on the relationship between HttpApplication and HttpModule, as well as a simple example implementation. (HttpModule is also the entry point for the MVC framework)

Figure 1

When the request arrives at the Web server and then goes to ASP, it constructs an HttpWorkerRequest object through ASP. HttpWorkerRequest is an abstract class type that represents some request processing information, which is then represented by the httpruntime in ASP. Type to call the static function ProcessRequest (), the parameter type is HttpWorkerRequest, because HttpWorkerRequest is abstract, when used should be an implementation class inside the system. Within the ProcessRequest () method, the HttpApplication object is generated, and the process between the Httpworkerpequest object is transformed into the HttpRequest object, The HttpRequest object is publicly accessible (not represented in the figure). At this time, instead of executing the HttpHandler program, the contents of the HttpModule are executed first, and they subscribe to events in HttpApplication to make a custom change between the various states of the request (these are mentioned in the following example.) Then execute the HttpHandler, after the handler executes, not to HttpResponse, but to the HttpModule to perform some custom actions after the request is completed, which is agreed in the HttpApplication, The response operation is done when all of these are done.

We will simulate the use model of events in the HttpApplication type in the following example.

Example section

Code 1-1

1      Public Delegate voidPassnotice (Noticecontext noticecontext);2 3      Public classOrder4     {5         PrivateNoticecontext _noticecontext;6 7          PublicNoticecontext Noticecontext8         {9             Get{return_noticecontext;}Ten             Set{_noticecontext =value;} One         } A  -         PrivatePassnotice _befpassnotice; -          Public EventPassnotice Befpassnotice the         { - Add -             { -_befpassnotice + =value; +             } - Remove +             { A_befpassnotice-=value; at             } -         } -  -         PrivatePassnotice _latpassnotice; -  -          Public EventPassnotice Latpassnotice in         { - Add to             { +_latpassnotice + =value; -             } the Remove *             { $_latpassnotice-=value;Panax Notoginseng             } -         } the  +         Private voidsendgoods () A         { theConsole.WriteLine ("shipping ... Please wait to receive"); +         } -  $          Public voidStart () $         { -             if(_befpassnotice! =NULL) -             { the _befpassnotice (noticecontext); -             }Wuyi  the             if(noticecontext.issend) -             { WuConsole.WriteLine ("server: Client confirmed to ship"); - sendgoods (); About                 if(_latpassnotice! =NULL) $                 { - _latpassnotice (noticecontext); -                 } -                 if(noticecontext.isaccept) A                 { +Console.WriteLine ("server: Client has received goods"); the                 } -             } $             Else the             { theConsole.WriteLine ("service side: Waiting for client to confirm"); the             } the  -         } in}
View Code

The Order class represents orders (a bit of an inappropriate analogy here) with two Passnotice delegate types of events Befpassnotice, Latpassnotice, Indicates the verification before the order shipment and the actions the customer can take after the shipment (corresponding to the various events in HttpApplication), and then look at the customer class

Code 1-2

1      Public classNoticecontext2     {3          Public BOOLIssend {Get;Set; }4          Public BOOLisaccept {Get;Set; }5     }6 7      Public classCustomer8     {9         PrivateOrder _order;Ten          PublicCustomer (Order order) One         { A_order =order; -_order.befpassnotice + =NewPassnotice (_order_befpassnotice); -_order.latpassnotice + =NewPassnotice (_order_latpassnotice); the         } -  -         void_order_latpassnotice (noticecontext noticecontext) -         { +Noticecontext.isaccept =true; -Console.WriteLine ("client: Receiving goods"); +         } A  at         void_order_befpassnotice (noticecontext noticecontext) -         { -  -Noticecontext.issend =true; -Console.WriteLine ("client: Can ship"); -         } in}
View Code

Here the customer class has a reference to the Order class and subscribes to the event of the Order class, which can be processed to the Noticecontex type value in the Order class (similar to HttpModule).

Call
Code 1-3

1             New Order (); 2             New Customer (order); 3             New false false  }; 4             Order. Start ();

As shown in result 2
Figure 2


There are many places in the example where there is no indication of white, only one approximate model is shown, and the order type corresponds to a single processing (in the case of a defect), as if HttpApplication can only correspond to a single request. The current context information is also just the information that holds the current request.
In code 1-3, the customer is called directly, but not in ASP.

The next article will talk about the route part of MVC, and for this preschool series, slowly refine it.

Jinyuan

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

This article is copyrighted by the author and the blog Park, welcome reprint, but without the consent of the author must retain this statement, and on the article page

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.