5
\$\begingroup\$

Should I leave the Default Route in if it's not adding any benefit?

I have a RouteConfig.cs file that looks like this:

public static void RegisterRoutes(RouteCollection routes)
{
 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 routes.MapRoute(
 name: "Dashboard",
 url: "{controller}/{action}",
 defaults: new { controller = "JobDashboard", action = "Index" }
 );
 routes.MapRoute(
 name: "Default",
 url: "{controller}/{action}/{id}",
 defaults: new { controller = "JobDashboard", action = "Index", enumDigit = UrlParameter.Optional }
 );
 routes.MapRoute(
 name: "Login",
 url: "{controller}/{action}",
 defaults: new { controller = "Account", action = "Login" }
 );
}

If I only have the Default and Login Routes and the user goes to the root of the site (eg www.sitename.com), then the user always goes to the Login page. I don't want them going to the Login page after they've logged in, and after a little bit of digging I discovered that MVC4 always sorts Route Order Importance by Custom Route first, and then the Default Route.

I created the Dashboard route, and everything is working fine. I then took out the Default route because it didn't seem needed. Nothing seems to be affected by removing the Default Route, and that leads me to the question, should I leave the Default Route in there?

I seem to recall that having a Default Route is good practice, but if it's not adding anything to the solution, is there a good reason to keep it around?

Malachi
29k11 gold badges86 silver badges188 bronze badges
asked Nov 27, 2013 at 18:41
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I am thinking that you would want to keep that default route in there in the case that something happens to the other routes, then there is something to route to if your custom routes get hosed up for some reason.

Defaults are there for a reason, don't get rid of them

answered Nov 28, 2013 at 20:56
\$\endgroup\$
2
  • \$\begingroup\$ What kind of "something" could happen to the other routes that would leave the default route unaffected? \$\endgroup\$ Commented Nov 29, 2013 at 0:45
  • \$\begingroup\$ Errors, Exceptions, someone trying to hack the site by putting things in there that aren't supposed to be there. I am not overly familiar with MVC structure, I just know that Defaults are there for a reason \$\endgroup\$ Commented Nov 29, 2013 at 1:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.