【问题标题】:How should I route CMS urls alongside optional paramters / actions in route config?我应该如何在路由配置中路由 CMS url 以及可选参数/操作?
【发布时间】:2013-07-16 17:35:18
【问题描述】:

我正在尝试将基本 CMS 添加到使用“url-formatted-string”作为 CMS 项目 ID 的 MVC 网站。

我花了很多时间试图满足下面列出的要求。但现在我想知道“有没有可能做到这一点?”

.

第一件事是我想支持“开箱即用”的 MVC url。

/news => NewsController.Index - I will set this to get the latest X items

/news/create => NewsController.Create

/news/edit/8 => NewsController.Edit - uses 8 as the id parameter

但我还希望在 /news/ 部分中支持 CMS 项目,并通过纯文本 URL 对其进行过滤。

/news/news-item-title => NewsController.Display - uses "news-item-title" as an id parameter

/news/search/search-term => NewsController.Search - uses "search-term" as a string parameter

最后,我想要一个默认的控制器/动作来获取没有定义控制器或动作的 URL。 (并为此适应正斜杠)。比如:

/services/consulting => CMSPageController.Index - defaults to CMSPage Controller and uses "services/consulting" as an id parameter

/about-us  = CMSPageController.Index - defaults to CMSPage Controller and uses "about-us" as an id parameter

这一切都可能吗,还是我应该放弃与 route_config 斗争?

【问题讨论】:

    标签: c# asp.net-mvc url content-management-system asp.net-mvc-routing


    【解决方案1】:

    最终我在这里偶然发现了答案:

    Dynamic Routes from database for ASP.NET MVC CMS

    答案是提供一个自定义路由约束来检查数据库是否存在 CMS url。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-10
      • 2014-10-12
      • 2023-03-27
      • 1970-01-01
      • 2015-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多