Using as many routes as possible Default .
For example:
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 },
namespaces: new [] { "SeuProjeto.Controllers" }
);
}
}
Only with these declarations, you have the path to all Controllers
of your application, defaulting to%% Index and Id as optional.
If your goal is to have alternate names for your routes, you can put the alternate routes before the Action
route or separate the alternate routes into another file. If you choose the separation path, be sure to call the two routing records in your Default
:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RotasAlternativasConfig.RegisterRoutes(RouteTable.Routes); // Crie um arquivo chamado RotasAlternativasConfig no diretório App_Start
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
}