software master at the intersection of technology, science and art

home

download

routing


Routing defines the URL pattern and handler infomation. All teh configured routes are stored in a RouteTable in the MVC architecture. The Routing Engine determines the handler class or file for an incoming request. The RouteTable is defined in the RouteConfig class under App_Start. Usually a default route is registered which is a model for the URI calls.

Example:


public static void RegisterRoutes(RouteCollection routes)
{

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");



routes.MapRoute((

name: "default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Home", acxtion="Index", id=UrlParameter.Optional}

);

} }

In the above, the default pattern for a URL request is the controller name/ the action/optional id. The default points to the Home/Index methods which is the usual start page for an MVC application. So "/" calls the default.


Additional routes amy be defined but must appear in a cascading order in the RegisterRoute method. The more specific routes must appear before the general routes and before the Default route.