Sitecore LinkManager url 编码

标签 sitecore

这看起来微不足道,但我在网上找不到现有的答案......

我正在使用 Sitecore,并且已将其配置为使用项目的显示名称来生成其 URL(使用“useDisplayName”设置)。

现在,当我有一个显示名称为“Test, with commä”的项目时 我希望 Sitecore 的 LinkManager 为我提供有效的 URL:

/nl-NL/ContentPage/Test%2C-with-comm%C3%A4

但是,它为我提供了一个 URL,其中包含未编码的无效字符:

/nl-NL/ContentPage/Test,-with-commä

现在我知道我可以对特定字符进行异常(exception)处理,但这不是重点。我希望 Sitecore 删除任何非法 URL 字符及其编码对应字符。

没有设置或简单的方法可以实现此目的吗?

最佳答案

不幸的是,Sitecore 不支持以您想要的方式对 url 部分进行编码。

并且 encodeNames="true" 仅告诉 Sitecore 使用 encodeNameReplacements 设置中配置的内容。

您有 2 个选择:

  1. 联系 Sitecore 支持并告知他们此错误。
  2. 覆盖 LinkProvider 类并对 URL 进行编码:
public class CustomLinkProvider : Sitecore.Links.LinkProvider
{
    public override string GetItemUrl(Item item, UrlOptions options)
    {
        var itemUrl = base.GetItemUrl(item, options);

        // your code to encode the url

        return itemUrl;
    }
}
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
  <linkManager>
    <providers>
      <add name="sitecore">
        <patch:attribute name="type">My.Assembly.Namespace.CustomLinkProvider,My.Assembly</patch:attribute>
      </add>
    </providers>
  </linkManager>
</sitecore>
</configuration>

关于Sitecore LinkManager url 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41829059/

相关文章:

sitecore - sitecore 发布后网站未更新

sitecore - 扩展 Sitecore WFFM 字段类型

sitecore - 仅注册一次 Sitecore 目标

asp.net - ascx中的Updatepanel刷新整个控件

c# - Sitecore 8.1 中可重用的组件集合

c# - 无法在 Sitecore 8.1 中定位元素(selenium 和 c#)

sitecore - Sitecore 8.0 发布选项

redirect - 网站显示 sitecore 登录页面

lucene - 如何使用 Sitecore 内容搜索和页面编辑器

Sitecore:占位符设置在应用于特定模板时不起作用