0

Is it necessary to map all the controllers/actions to the route table in MapRoute function in an application ?

If not so, then how they added to the route tables ?

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
Anandh
  • 57
  • 1
  • 1
    Not unless you want specific routes (the default route will cater for most cases) –  Feb 02 '18 at 12:14

1 Answers1

0

Using the default convention-based route will cover basic routing for many cases, especially those that aren't concerned so much with what the URL looks like. Since there is only 1 route in the route table, this is the best performing option, and it automatically "just works" for any controller or action that is added to the project.

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

Typically, other than that URLs are statically added either by using the MapRoute method or [Route] attributes, meaning they are compiled into the application and cannot change at runtime. This makes routes testable so the configuration can be verified before release.

However, if the goal is to make some sort of CMS where the application has control over the URLs and you want them to automatically be "made live" as you add records to your database you can extend RouteBase to handle that (along with virtually any other) routing scenario.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212