Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kentico 子文档能否继承其自定义URL路径';她在肯蒂科的父母_Kentico - Fatal编程技术网

Kentico 子文档能否继承其自定义URL路径';她在肯蒂科的父母

Kentico 子文档能否继承其自定义URL路径';她在肯蒂科的父母,kentico,Kentico,我有一种情况,我的客户希望他们的文档有SEO友好的URL,并且这些URL向下流到客户文档。以下是一个示例设置: 根 团体 Group1(自定义url=/groups/ma/salem/Group1) 第1页 第2页 Group2(自定义url=/groups/ma/boston/Group2) 第2页 第4页 等等 希望Page1、Page2、Page3、Page4继承其父级的自定义url,并为: /组/ma/salem/group1/page1 /组/ma/salem/gro

我有一种情况,我的客户希望他们的文档有SEO友好的URL,并且这些URL向下流到客户文档。以下是一个示例设置:

  • 团体

    • Group1(自定义url=/groups/ma/salem/Group1)

      • 第1页
      • 第2页
    • Group2(自定义url=/groups/ma/boston/Group2)

      • 第2页
      • 第4页
    • 等等
希望Page1、Page2、Page3、Page4继承其父级的自定义url,并为:

  • /组/ma/salem/group1/page1
  • /组/ma/salem/group1/page2
  • /组/硕士/波士顿/组2/page2
  • /组/硕士/波士顿/组2/page3
设置自定义URL路径时,它只影响该文档,子文档保持不变:

  • /组/组1/page1
  • /组/组1/page2
  • /组/组2/page2
  • /组/组2/第3页
这可以在Kentico中实现,而无需修改树结构以包含URL部分吗

有没有方法重写ResolveURL()函数,以便返回SEO友好的URL


我使用的是Kentico 8.1,在树中创建这些文档肯定是最简单、最安全的解决方案,但是如果您想避免这种情况,我看到了另外两种选择

1) 创建URL重写规则以模拟此树层次结构

2) 捕获事件之前的文档插入,并根据需要设置自定义URL路径

代码可以如下所示:

DocumentEvents.Insert.Before += DocumentInsert_Before;

private static void DocumentInsert_Before(object sender, DocumentEventArgs e)
{
    TreeNode node = e.Node;

    if (node.NodeAliasPath.StartsWith("/groups/group1")) {
        string safeNodeName = TreePathUtils.GetSafeDocumentName(node.DocumentName, CMSContext.CurrentSiteName);
        string customPath = "/groups/ma/salem/group1/" + safeNodeName;

        // Handle multiple dashes
        customPath = TreePathUtils.GetSafeUrlPath(path, CMSContext.CurrentSiteName, true);

        node.DocumentUrlPath = customPath;
    }
}