RoutingMVC.md - brainchildservices/curriculum GitHub Wiki

SLIDE-1

ROUTING IN MVC

SLIDE-2

Route

The ASP.NET Routing module is responsible for mapping the incoming browser requests (i.e. the incoming URL) to a particular MVC controller action method. This mapping is done by the routing rules defined for your application. For example, if we issue a request to the “/Home/Index” URL, then it is the Index action method of Home Controller class which is going to handle the request as shown in the below image.

Screenshot 2021-06-19 at 12 11 35 PM

Routing is not new or specific to ASP.NET MVC framework. It can also be used with our traditional ASP.NET WebForms application.

SLIDE-3

What is a Route in ASP.NET MVC Application?

A Route is a URL pattern that is mapped to a handler. The handler can be a physical file, such as an aspx file in case of WebForms application. A handler can also be a class that processes the request, such as a controller in case of an MVC application. That means the Route defines the URL pattern and the handler information. All the configured routes of an ASP.NET MVC application stored in the RouteTable and this Route table will be used by the Routing engine to determine the appropriate handler class or file for an incoming request.

SLIDE-4

How Does the Routing work in ASP.NET MVC Application?

The following diagram illustrates the Routing process.

Screenshot 2021-06-19 at 12 15 34 PM

In simple word, we can say that ASP.NET MVC Routing is a pattern matching mechanism that handles the incoming request (i.e. incoming URL) and figures out what to do with that incoming request (i.e. incoming URL).

At runtime, Routing engine uses the Route table for matching the incoming request’s URL pattern against the URL patterns defined in the Route table. We can register one or more URL patterns to the Route table at Application_Start event.

When the routing engine finds a match in the routing table for the incoming request, it forwards the request to the appropriate controller and action. If there is no match found in the routing table for the incoming request, then it simply returns a 404 HTTP status code.