My ASP.NET MVC 5 project is multilingual and I use culture to change the language.
I have defined the default routing with culture as follows:
public static void RegisterRoutes(RouteCollection routes)
{
var _cul = CultureHelper.GetCurrentCulture() != null
? CultureHelper.GetCurrentCulture()
: ConfigurationSettings.AppSettings["WebSiteDefaultCulture"];
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
"Default",
"{culture}/{Controller}/{action}/{id}",
new {culture = _cul, controller = "Home", action = "Index", id = UrlParameter.Optional}
);
routes.MapRoute(
"Home",
"{culture}/Home/{action}/{id}",
new {action = "Index", id = UrlParameter.Optional}
);
}
So the URL of all pages of the site will be opened only with culture.
I want to open some specific site URLs without culture.
For example, this URL https://test.com/en-US/Cart/Cart/5 can be opened without providing a culture.
Thanks.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The solution is to define two routing, with and without culture
routes.MapRoute(
name: "DefaultWithCulture",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { culture = _cul }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { culture = _cul, controller = "Home", action = "Index", id = UrlParameter.Optional }
);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0