The reason that ASP. NET core is a Web development platform is that it has a highly extensible request processing pipeline that we can customize to meet the HTTP processing needs of various scenarios. Asp. NET core applications, such as routing, authentication, sessions, caching, and so on, also customize the message processing pipeline to achieve. We can even create our own web framework on the ASP. In fact, the two important web frameworks of MVC and SINGALR are created in this way.
I. Using pipelines to process HTTP requests
The nature of the HTTP protocol itself determines that any Web application works by listening, receiving, and processing HTTP requests and finally responding to requests, and HTTP request processing is a typical application scenario for piping design. We customize a message processing pipeline based on the processing process of the HTTP request, allowing incoming HTTP request messages to flow into the pipeline like water, making each link of the pipeline a corresponding treatment at a time. The result of the processing is also turned into a message that flows back into the pipeline for processing and eventually translates into an HTTP response to the client. The message processing pipeline for ASP. NET core is very simple from the point of view of design, but it is relatively difficult to understand from the point of view of concrete implementation, in order to let readers have a deep understanding of this chapter, we start from the simple part. [Read the full text]
Second, create a "mini-version" of the pipeline to simulate the real pipeline request processing process
We know that the ASP. NET core request processing pipeline consists of a server and a set of ordered middleware, so it is very simple in terms of overall design, but as far as the specific implementation is concerned, because of the interaction of many objects, I think very few people will be able to figure it out. If you want to get a very deep understanding of ASP. NET core's request processing pipeline, which can be done in two steps, we can first understand the overall flow of the pipeline processing HTTP requests without the details, and then supplement the details previously omitted. To make it easier for readers to understand the overall flow of the pipeline processing HTTP requests, we reconstructed a "simulation pipeline" based on the implementation principle of the real pipeline. [Read the full text]
Third, how is the pipeline handling HTTP requests?
The ASP. NET core request processing pipeline is a combination of a server and a set of ordered middleware. We can make a further abstraction on this basis and abstract the latter into a HttpApplication object, then the pipeline becomes a complex of servers and HttpApplication (5). The server forwards the received HTTP request to the HttpApplication object, which creates a context for the current request, processes the request in this context, and then httpapplication the context with the reclamation release processing after the request processing is complete and the response is completed. [Read the full text]
Iv. How is the pipeline created?
The request processing pipeline involves four core objects, namely Webhostbuilder, webhost, Server, and HttpApplication, which have a relationship of 11. We create the webhost through Webhostbuilder and lead the latter to build the request processing pipeline.
The request processing pipeline consists of a server and a HttpApplication object, which encapsulates all the registered middleware. When Webhost is started, it creates the server and HttpApplication objects and calls the server's Start method as a parameter to start the server. The startup server opens a listen request and uses HttpApplication to process the received request. When HttpApplication completes all the request processing work, it uses the server to complete the final response to the request. [Read the full text]
ASP. NET core pipeline depth analysis [total 4 articles]