asp.net mvc - C# MVC Rote custom configuration -


i have:

routes.maproute(             name: "default",             url: "{culture}/{controller}/{action}/{id}",             defaults: new { culture = "en-us", controller = "home", action = "index", id = urlparameter.optional }         ); 

that makes urls this:

www.site.com/en-us/contactus/index

www.site.com/es/contactus/index

my question how configure routes when "culture" "en-us" urls this:

www.site.com/contactus/index

but when "culture" "es" or other culture (besides en-us) urls (example below "es" culture):

www.site.com/es/contactus/index

your routes should follows:

    public static void registerroutes(routecollection routes)     {         routes.ignoreroute("{resource}.axd/{*pathinfo}");          routes.maproute(             name: "culture",             url: "{culture}/{controller}/{action}/{id}",             defaults: new { culture = "en-us", controller = "home", action = "index", id = urlparameter.optional }         );         routes.maproute(             name: "default",             url: "{controller}/{action}/{id}",             defaults: new { culture="en-us", controller = "home", action = "index", id = urlparameter.optional }         );     } 

the idea when receive url culture first route handle it.

otherwise, if receive route without culture, default route take care of "hard coding" default culture.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -