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" }
);
}
}
Just with these statements, you have the route to all Controllers
of its application, having as a standard the Action
Index and the Id parameter as optional.
If the goal is to have alternative names for your routes, you can put alternative routes before the route Default
or separate alternative routes into another file. If you choose the separation path, don’t forget to call the two route records in your Global.asax.cs
:
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();
}
}
+1 for
MvcRouteTester
. Very good.– Leonel Sanches da Silva
I recommend using the Glimpse. You can see the routes and values well, as well as other detailed information about what is happening on the server.
– Jone Polvora