当前位置:网站首页>ASP. Net core introduction V

ASP. Net core introduction V

2022-07-07 22:37:00 51CTO

ASP.NET Core ( Request processing pipeline )

understand ASP.NET Processing pipeline

In order to understand ASP.NET Core Request processing pipeline concept in , Let's revise Startup Class Configure() Method , As shown below . ad locum , We register three middleware components into the request processing pipeline . As you can see , The first two components are used Use() Extension method registered , So they have the opportunity to call the next middleware component in the request processing pipeline. . Last use Run() Extension method registration , Because it will become our termination component , That is, it will not call the next component .

ASP.NET Core Introduction 5 _ Request processing

understand ASP.NET Core Request processing pipeline execution order

To understand this , Let's compare the above output with the following figure , Understand in a simpler way ASP.NET Core Request processing pipeline .
ASP.NET Core Introduction 5 _asp.net_02

When incoming HTTP When the request arrives , It starts with the first middleware component ( namely Middleware1) receive , This component is recorded in the response flow “ Middleware1: incoming request ”. therefore , First , We first see this message on the browser .

The first middleware Recorded information , Then it will call next() Method , This method will invoke second Middleware in the request processing pipeline. , namely Middleware2.

The second middleware Recorded “ middleware 2: incoming request ” Information , So we see the log information after the first log . Then the second middleware call next(), It will invoke third Middleware in the request pipeline. Middleware3.

The third middleware Processing requests , Then generate a response . therefore , The third message we see in the browser is “ Middleware3: The incoming request was processed and a response was generated ”.

The middleware component uses Run() Extension method registered , So it's a terminal component . therefore , From this point on , Request the pipeline to start reverse . This means that control is handed back from the middleware to the second middleware , The second middleware records the information as “ middleware 2: Outgoing response ”, Control is then returned to the first middleware component , The first middleware component records information, just as we can see in the browser , yes “ Middleware1: Outgoing response ”.

Key points to remember :
ASP.NET Core The request processing pipeline consists of a series of middleware components , These middleware components will be called one by one .
Each middleware component can be used in next Method performs some operations before and after calling the next component . The middleware component can also decide not to call the next middleware component , This is called a short circuit request pipeline .
asp.net Middleware components in the core can access incoming requests and outgoing responses .
The most important thing you need to keep in mind is , stay Startup Class Configure The order in which middleware components are added to the method defines the order in which these middleware components will be called upon request and the reverse order to them . Respond to . therefore , Sequence is important for defining the security of an application , Performance and functionality are critical .

Should be . therefore , Sequence is important for defining the security of an application , Performance and functionality are critical .

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207072135075905.html