|
|
Posted on 2021-5-12 11:21:52
|
|
|
|

Middleware is a type of software that is assembled into an application pipeline to handle requests and responses. Each component:
- Choose whether to pass the request to the next component in the pipeline.
- Work can be performed before and after the next component in the pipeline.
Request delegation is used to build a request pipeline. Request delegates to handle each HTTP request.
Documentation:The hyperlink login is visible.
Review:
ASP.NET Core MiddlewareMiddleware is registered in a singleton model, that is, the application will only be instantiated once and the constructor will only be initialized once from start to finish.
First, let's create a new TestMiddleware middleware with the following code:
Register in the Configure method of the startup file, as follows:
Middleware intercepts direct response requests
Try to intercept the request for the /home/index2 path and directly respond to a piece of JSON message, the code is as follows:
Middleware middleware passes parameter values
Sometimes, we need to pass some parameter configurations to middleware, such as: intercepted address, response information, etc.
UseMiddleware() method to pass the params object[] parameter to the middleware's constructor, which means that we can pass any number of parameters to the middleware through params object[], as long as the type and the middleware's constructor parameters match.
It can be passed by code like this:
Middleware middleware is passed between values
Create a new Test2Middleware middleware, we register multiple middleware at the same time, and the subsequent middleware needs to do some logical processing according to the previous middleware, that is, pass parameters between middleware, the code is as follows:
Middleware OnStarting responds to the delegation
Because middleware can register multiple and may go through multiple intermediate processes, the last middleware wants to do something before responding, it can register an OnStarting delegate. The test will perform a header change in the context of HttpResponse.OnStarting(Func<Task>) to ensure that the callback is executed immediately before flushing the response to the client.
The code is as follows:
(End)
|
Previous:EF Entities of append type "XXXX" fail because other...Next:POI uses three methods: HSSF, XSSF, SXSSF
|