0

I have website using Drupal. Now, I want to using Asp.net MVC to build a similar website, but I could not config routing like in Drupal.

In Drupal:

  1. /: home page, default language: vi
  2. /{lang}: home page in language {lang}
  3. /{catePermanentLink}: list news article of category, default language: vi
  4. /{lang}/{catePermanentLink}: list news article of category in language {lang}
  5. /{catePermanentLink}/{newsPermanentLink}: view news detail, default language: vi
  6. /{lang}/{catePermanentLink}/{newsPermanentLink}: view news detail, in language {lang}
  7. /{catePermanentLink_Level1}/{catePermanentLink_Level2}: list news article of category, default language: vi
  8. /{lang}/{catePermanentLink_Level1}/{catePermanentLink_Level2}: list news article of category in language {lang}

How I can config in Asp.net MVC. Nice thanks.

cuvu
  • 43
  • 7
  • What are the controller methods associated with each, and what do you want the url to look like? for example for No. 5, do you want `../fr/News/Detail/10` (or perhaps just `..fr/Details/10`) to show the details of the News item with `ID=10` in French? –  Feb 26 '17 at 03:46
  • This question is rather vague for those not familiar with Drupal, but [this answer](http://stackoverflow.com/a/32839796/181087) may get you in the right direction. – NightOwl888 Feb 26 '17 at 18:28
  • {root}/{catePermanentLink}/{newsPermanentLink} ==> News detail with default language. {root}/fr/{catePermanentLink}/{newsPermanentLink} ==> News detail with FR language – cuvu Feb 27 '17 at 03:07

1 Answers1

0

Thanks all. I share my working config

//Ưu tiên Search
        routes.MapRoute(name: "search", url: "{lang}/search/{keyword}", defaults: new { controller = "search", action = "result" });

        //Normal with Language
        routes.MapRoute(
            name: "Language",
            url: "{lang}",
            defaults: new { controller = "Home", action = "Index", lang = UrlParameter.Optional },
            constraints: new { lang = @"(\w{2})" }
        );

        //News Category
        routes.MapRoute(
            name: "defaultLanguageWithCate",
            url: "{cateSlug}",
            defaults: new { lang = "vi", controller = "News", action = "NewsByCate" },
            constraints: new { lang = @"(\w{2})", controller = "News", action = "NewsByCate" },
            namespaces: new[] { "Frontend.Web.Controllers" }
          );

        routes.MapRoute(
            name: "languageWithCate",
            url: "{lang}/{cateSlug}",
            defaults: new { lang = "vi", controller = "News", action = "NewsByCate" },
            constraints: new { lang = @"(\w{2})", controller = "News", action = "NewsByCate" },
            namespaces: new[] { "Frontend.Web.Controllers" }
         );

        //News Detail
        routes.MapRoute(
           name: "defaultLanguageWithArticle",
           url: "{cateSlug}/{articleSlug}",
           defaults: new { lang = "vi", controller = "News", action = "Detail" },
           constraints: new { lang = @"(\w{2})", controller = "News", action = "Detail" },
           namespaces: new[] { "Frontend.Web.Controllers" }
        );

        routes.MapRoute(
             name: "languageWithArticle",
             url: "{lang}/{cateSlug}/{articleSlug}",
             defaults: new { lang = "vi", controller = "News", action = "Detail" },
             constraints: new { lang = @"(\w{2})", controller = "News", action = "Detail" },
             namespaces: new[] { "Frontend.Web.Controllers" }
       );

        //Không có Language
        routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, lang = "vi" }
          );
cuvu
  • 43
  • 7