Microsoft.AspNetCore.Routing
Endpoint
Represents a specific code path that can be executed in response to a request.
Properties
- DisplayName: string
- Metadata: EndpointMetadataCollection
- RequestDelegate: RequestDelegate
Methods
- ExecuteAsync(HttpContext context)
Remarks
Endpoints are the fundamental unit of routing in ASP.NET Core. They represent the final destination for a request after routing has occurred. An endpoint typically includes a delegate that handles the request and associated metadata for further processing.
Example
// Example of creating a simple endpoint
var endpoint = new RouteEndpoint(
async context => { await context.Response.WriteAsync("Hello from Endpoint!"); },
new RoutePatternFactory().Parse("/hello"),
0, // Order
new EndpointMetadataCollection(),
"HelloEndpoint"
);
RouteMatcher
A matcher that evaluates requests against a collection of routes.
Constructors
RouteMatcher(IEnumerable<Endpoint> endpoints)RouteMatcher(IEnumerable<Endpoint> endpoints, RouteMatcherOptions options)
Methods
- MatchAsync(HttpContext httpContext, IRouter next)
Remarks
RouteMatcher is a core component of ASP.NET Core's routing system. It iterates through a set of endpoints and attempts to match the current HTTP request against their associated route patterns. The first matching endpoint's delegate is then executed.
RouteOptions
Configuration options for routing.
Properties
- BasePath: string
- ConstraintMap: IDictionary<string, Type>
- RouteMatchingDelegate: RequestDelegate
- SuppressImplicitRequiredAttributeForEnum: bool
- SuppressImplicitRequiredAttributeForNullableInt32: bool
Remarks
RouteOptions allows for customization of how routing behaves within an ASP.NET Core application. This includes defining custom route constraints, specifying a base path for all routes, and configuring behavior related to route parameter validation.
Route
Represents a single route definition.
Properties
- Defaults: object
- RouteName: string
- RouteTemplate: string
Methods
- GetVirtualPath(VirtualPathContext context)
- MatchAsync(HttpContext httpContext, IRouter next)
Remarks
The Route class defines a specific route, including its template, default values for parameters, and constraints. It plays a crucial role in both matching incoming requests to an action and generating URLs for a given route.
RouteBuilder
Builds a router for the application.
Properties
- ApplicationBuilder: IApplicationBuilder
- DataSources: IList<EndpointDataSource>
Methods
- Build()
- MapGet(string pattern, RequestDelegate requestDelegate)
- MapPost(string pattern, RequestDelegate requestDelegate)
- UseRouter(IRouter router)
Remarks
RouteBuilder is used within the ASP.NET Core middleware pipeline to configure the routing system. It allows developers to define routes, add middleware to the routing pipeline, and ultimately construct the IRouter that will handle request matching.