Home  >  Article  >  Backend Development  >  What are the three parts of default routing in ASP .Net MVCC#?

What are the three parts of default routing in ASP .Net MVCC#?

WBOY
WBOYforward
2023-09-16 23:33:02982browse

ASP.Net MVC routing module is responsible for mapping incoming browsers A request for a specific MVC controller action. When an ASP.NET MVC application Launched, the application then registers one or more schemas with the framework The routing table tells the routing engine how to handle any requests that match these model. When the routing engine receives a request at runtime, it matches the request The requested URL corresponds to the registered URL pattern and the response is given Match based on pattern.

ASP.NET introduced routing to eliminate mapping each URL to a Physical files. Routing allows us to define URL patterns that map to requests handler. System.Web.Routing is used by the MVC framework, but is also ASP.NET dynamic data. MVC framework uses routing to guide requests to the controller. The Global.asax file is part of our application where we will Define the routes for our application.

The following is the routing configuration for the MVC application -

public class RouteConfig{
   public static void RegisterRoutes(RouteCollection routes){
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
      routes.MapRoute(
            name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
      );
   }
}

Route Name

A route is a URL pattern that is mapped to a handler. Handlers can be controllers An MVC application that handles requests. Route names can be used as A specific reference to a given route.

Constraints

A set of constraints applied against a URL pattern to more narrowly define The URL it matches.

URL Pattern

URL pattern can contain literal values ​​and variable placeholders. text and Placeholders are located in portions of the URL separated by slashes (/) character.

When a request is made, the URL is parsed into segments and placeholders, and The variable value is provided to the request handler. This process is similar to The data in the query string is parsed and passed to the request handler. In both cases Variable information is included in the URL and passed to the handler in the form Key-value pairs. For query strings, both the key and the value are in the URL. for Routes where the keys are placeholder names defined in the URL pattern and only The value is in the URL.

Default value

When we define a route, we can assign default values ​​to parameters. The default value is Object containing default route values. Three segments of the default route Contains controller, action and ID.

ASP .Net MVCC# 中默认路由的三个部分是什么?

In the above URL, the corresponding controller and action will be matched. if we are Controllers and action methods in URL are not sent and based on default values The route's corresponding controller action method will be called.

ASP .Net MVCC# 中默认路由的三个部分是什么?

The above is the detailed content of What are the three parts of default routing in ASP .Net MVCC#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete