Route definition: responsible for matching incoming HTTP requests and distributes these requests to perform endpoint applications. Routing using "end point" ( Endpoint
) used to represent a logical endpoint application
Endpoint: requesting application is an executable code processing units, defined in the application, and configured at application startup, termination matching process may be extracted from the request url value, and provide these values to the requesting process
Endpoint Routing: routing endpoint has templates, metadata, and delegates the request to service endpoints response by the integration of two extension method using middleware
1.UseRouting add a route to match the middleware pipeline. Before you must be aware middleware (authorization, endpoint execution, etc.) on any route, role: to find the endpoint based on the current request
2.UseEndpoints added to the broker pipe endpoint action: The endpoint to final processing execution request, a specific action is to find a method
Official Sample Code
public void Configure(IApplicationBuilder app) { // Matches request to an endpoint. app.UseRouting(); // Endpoint aware middleware. // Middleware can use metadata from the matched endpoint. app.UseAuthorization(); // Execute the matched endpoint. app.UseEndpoints(endpoints => { // Configuration of app endpoints. endpoints.MapRazorPages(); endpoints.MapGet("/", context => context.Response.WriteAsync("Hello world")); endpoints.MapHealthChecks("/healthz"); }); }
Introduces the basics of the front, then why exactly after 3.x endpoint routing system to introduce it?
In version 2.x, in response to a request of the process is such that:
Upon receiving a request, through a series of intermediate conduit events that ultimately send the http request by the intermediate route and route data to the router handler mvc, and then route the data request by the matching route mvc Handler, i.e. to match the controller action method for processing a request, and then executes the selected intermediate router action method for generating a response, the final response to the client backtrack.
Then after 3.x changes:
Endpoint 2 from the routing intermediate composition, i.e. above the Endpoint and the Routing Endpoint i.e. corresponding to the upper and UseEndpoints UseRouting
Why would it do that? ? ?
Vernacular: but then actually be executed before the router middleware middleware is unfriendly, such as authorization middleware can not know in advance that the request will be executed which action methods, and better distinguish mvc, decoupling
The official explanation:
- Endpoints and middleware good choreography with other ASP.NET Core-based technologies (such as health checks).
- Endpoints can implement various strategies in middleware and MVC, such as CORS or authorization
- And a filter characteristic (attribute) can be placed on the method in the controller.
Reference documents:
https://mp.weixin.qq.com/s/ptFa4-s6PVgPU-qB7XRXWg