What is routing in C# ASP.NET Core?

WBOY
Release: 2023-08-25 22:37:06
forward
785 people have browsed it

C# ASP.NET Core 中的路由是什么?

Routes are used to map requests to route handlers.

Routes are configured when the application starts and can be accessed from The URL that will be used for request processing.

Routing basics

Routing uses routing (implementation of IRouter)

  • Map incoming request routing handler
  • Used in generating responses URL

Routes are connected to the middleware pipeline through the RouterMiddleware class. ASP.NET MVC adds routes to the middleware pipeline as part of its configuration

URL matching

Incoming requests go into the RouterMiddleware that calls the RouteAsync method

IRouter instance is set by RouteContext handler for a non-null RequestDelegate.

If the handler has a route set, it will be called to handle the request and will go no further Routing will be processed.

If all routes are executed and no handler for the request is found, the middleware will call next and the next middleware in the request pipeline are called.

URL Generation

URL generation follows a similar iterative process, but starts with the user or frame Code that calls the route collection's GetVirtualPath method.

Each route then calls its GetVirtualPath method in sequence until Returns non-null VirtualPathData

Create route

Routing provides the Route class as the standard implementation of IRouter. Routes use route template syntax to define what will be used with The URL path when calling RouteAsync.

When GetVirtualPath is , Route will use the same route template to generate the URL transfer.

Example

routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
Copy after login

The framework provides a set of extension methods for creating routes, such as -

MapRoute
MapGet
MapPost
MapPut
MapRoute
MapVerb
Copy after login

The above is the detailed content of What is routing in C# ASP.NET Core?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!