Tag: MSDN Send Request Book action object new Tle play IIS
Request Processing Pipeline
The request pipeline is a combination of the modules that are used to process HTTP requests, and in ASP., the request pipeline has two core components: a IHttpModule and IHttpHandler . All HTTP requests IHttpHandler are entered, with the IHttpHandler final processing, and IHttpModule through HttpApplication the events in the subscription object, the request can be preprocessed or processed after the HTTP request is processed IHttpHandler before processing the HTTP request IHttpHandler .
Before IIS7, such as IIS6 or IIS5, the request processing pipeline is divided into two: the IIS request processing pipeline and the ASP. If the client requests a static resource, only the IIS pipeline is processed, and the ASP. NET pipeline does not process the request. The two pipelines are merged from IIS7 and are called integrated pipelines.
The main description in the ASP. NET runtime handles HTTP requests and does not involve too much detail.
HttpApplication and HttpModule
After the HTTP request is taken over by the ASP. NET runtime, HttpRuntime It takes advantage of HttpApplicationFactory creating or from the HttpApplication object pool (. NET, a similar mechanism in the thread pool and string detention pool) takes an object out of it, and the HttpApplication ASP initializes the registration based on the configuration file HttpModule , and HttpModule at initialization it subscribes to the events in HttpApplication to implement the processing of the HTTP request.
In ASP. MVC5, Global.asax A class is defined in the file MvcApplication and inherits from the HttpApplication class:
public class mvcapplication:system.web.httpapplication{    protected void Application_Start ()    {        Arearegistration.registerallareas ();        ROUTETABLE.ROUTES.ADD ("Xfhhandler", New Route (           "{controller}/{action}", New            routevaluedictionary (new Dictionary<string, object> () {["Controller"] = "Home", ["action"] = "Index"}),            new Xfhurlroutehandler ()) c17/>);        Routeconfig.registerroutes (routetable.routes);    }}
Application_Start()Method is executed first, typically adding some configuration to the method, such as routing registration, Global filter registration, and so on.
Route
An HTTP request passes at least one HttpModule processing. UrlRoutingModuleis a very important module, it is the core of the routing system. The responsibility of the routing system is to obtain the name of the Controller and action and other request data from the request URL.
UrlRoutingModuleMatches the currently requested URL with the RouteTable registered route template and returns the first path that matches the current request Route , and then gets the route data object based on the Path object RouteData (ASP. The routing data must contain the name of the controller and the action, and then the RouteData fetch is IRouteHandler eventually IRouteHandler obtained IHttpHandler .
HttpHandler
An HTTP request is eventually processed into Httphanler, and an HTTP request can only be processed by one HttpHandler.
Controller
IHttpHandlerThe ProcessRequest current request is processed in the method, in the method, by ControllerBuilder obtaining IControllerFactory the type that is then obtained by reflection. Controller
Action
in ASP. NET MVC ControllerBase is all Controller the base class that executes the call to the method in that type of method Execute IActionInvoker InvokeAction Action . Actionmodel bindings and model authentication operations are performed prior to execution.
Filters
There are 5 commonly used filters in ASP. MVC5:,,,, IAuthenticationFilter IAuthorizationFilter IActionFilter IResultFilter IExceptionFilter .
In ASP. All filters are eventually encapsulated as Filter objects, and the properties and type attributes of the types in the object are FilterScope Scope used to determine the order in which the filters are executed, with the int Order following rules:
 
 
  
  OrderThe smaller the FilterScope number of values, the higher the priority of the filter execution;  
  OrderHigher FilterScope priority than is considered at the Order same time as the property value FilterScope  
 
 
The smaller the value, the higher the execution priority public enum filterscope{    action=,    controller=,    first= 0,    global=,    last= 100}
ActionResult
ActionAfter execution ActionResult , the type object is returned as the result of processing this request, and for a ActionResult return value that is not a type, ASP. NET MVC converts it to a ActionResult type.
Request Life cycle
The life cycle of an ASP. NET application begins with the browser sending a request to the WEB server, entering the processing pipeline after the request arrives at the server, and until the browser receives the server response.
Finally, I enclose a foreigner-drawn ASP. NET request pipeline diagram from the "ASP. NET MVC interview Questions and Answers book".
Bibliography Recommendations
ASP. NET MVC interview Questions and Answers book
"The Secret of the ASP. MVC5 Framework"
Reference articles
Overview of the ASP. NET application life cycle for IIS 7.0
The IIS7 Integrated Pipeline
Reprinted from: https://www.cnblogs.com/Cwj-XFH/p/6752177.html
ASP. MVC5 request pipeline and life cycle