InterviewSolution
| 1. |
What is Routing in ASP.NET MVC? |
|
Answer» Routing in ASP.NET MVC is a pattern matching system that maps the incoming requests from the BROWSER to specified actions of the MVC controller. When the application of ASP.NET MVC gets started, it registers one or multiple patterns with the framework route table so that it can inform the routing engine that what has to be done with the requests that are matching with those patterns. When a request is received by the routing engine during runtime, it matches that URL of the request against its registered URL patterns and PROVIDES the response based on a pattern match. The URL pattern in routing will be considered based on the domain name part in the URL. For example, the URL pattern "{controller}/{action}/{id}" will look similar to localhost:1234/{controller}/{action}/{id}. Anything that comes after the"localhost:1234/" will be considered as the name of the controller. In the same manner, anything that comes after the controller name will be considered as the name of the action and then comes the id parameter value. If the URL has nothing after the domain name, then the request will be handled by the default controller and action method. For example, the URL http://localhost:1234 will be handled by the Index() method and by the HomeController as per the default parameter configuration. The below-given route table will show which CONTROLLERS, Action methods, and Id parameters will be HANDLING the various URLs according to the above-provided default route. The below figure shows request processing by routing engine and response sent by it. It provides a response based on URL match in the route table. When the URL of the request matches any of the route patterns that are registered in the route table then the request will be forwarded by the routing engine to the suitable handler for that request. Later the route will be processed and obtain a view on the UI. When the URL of the request doesn’t match with any of the route patterns that are registered, the routing engine will indicate that it can’t determine how to do request handling by returning an HTTP STATUS code 404. |
|