[英]How to config Asp.net 5 MVC routing like Drupal?
I have website using Drupal. 我有使用Drupal的网站。 Now, I want to using Asp.net MVC to build a similar website, but I could not config routing like in Drupal. 现在,我想使用Asp.net MVC构建类似的网站,但是我无法像Drupal一样配置路由。
In Drupal: 在Drupal中:
How I can config in Asp.net MVC. 我如何在Asp.net MVC中进行配置。 Nice thanks. 很好,谢谢。
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" }
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.