【问题标题】:Dynamic routing in nopcommerce 3.9nopcommerce 3.9 中的动态路由
【发布时间】:2017-08-24 08:51:35
【问题描述】:

我是第一次尝试 nopcommerce。在探索它时,我发现有一个 url http://localhost:15536/apple-macbook 其中 apple-macbook 是产品名称。

我想知道这种动态路由是如何完成的。我有什么想法吗?

【问题讨论】:

    标签: routing nopcommerce


    【解决方案1】:

    返回 nopCommerce 3.9 你会在这里找到路由定义

    .../Nop.Web/Infrastructure/GenericUrlRouteProvider.cs

    routes.MapGenericPathRoute("GenericUrl",
        "{generic_se_name}",
        new {controller = "Common", action = "GenericUrl"},
        new[] {"Nop.Web.Controllers"});
    

    .MapGenericPathRoute() 可以在 .../Nop.Web.Framework/Seo/GenericPathRouteExtensions.cs

    中找到

    这个 GenericPathRoute 将查找数据库(UrlRecord 表),如果有匹配的请求,它将请求重定向到找到的实体的控制器。

    在你的情况下,这意味着重定向到

    case "product":
    {
        data.Values["controller"] = "Product";
        data.Values["action"] = "ProductDetails";
        data.Values["productid"] = urlRecord.EntityId;
        data.Values["SeName"] = urlRecord.Slug;
    }
    

    使用上面的 RouteData 调用 ProductController 上的 ProductDetails 操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 2020-02-29
      • 2011-08-07
      • 1970-01-01
      相关资源
      最近更新 更多