Home > Article > Backend Development > What are the three parts of default routing in ASP .Net MVCC#?
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 } ); } }
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.
A set of constraints applied against a URL pattern to more narrowly define The URL it matches.
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.
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.
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.
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!