0

If i go to mysite/Catalog it breaks. How can solve it?

routes.MapRoute(
    "Localization", // Route name
    "{lang}/{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);

routes.MapRoute(
    "Root",
    "",
    new { controller = "Home", action = "Index", id = "" }
);

1 Answer 1

2

It will match your first route thinking "Catalog" is "lang". You need to create constraint for your localizations.

Following route should match requests prefixed with any language code (like en, cs, de or en-US, en-GB...) correctly

routes.MapRoute("Localization", "{lang}/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new { lang = "[a-z]{2}(-[a-z]{2})" }
);
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.