C# Sitecore URL优化和语言
在Sitecore 6.2中使用多语言站点时,我希望能够使用连字符将URL中的Sitecore替换为“”(空白,传统上替换为%20) 例如:www.MySite.com/Hello-World>www.MySite.com/Hello-World 到目前为止没有问题,我们只需向encodeNameReplacements添加另一个条目C# Sitecore URL优化和语言,c#,web-config,sitecore,sitecore6,C#,Web Config,Sitecore,Sitecore6,在Sitecore 6.2中使用多语言站点时,我希望能够使用连字符将URL中的Sitecore替换为“”(空白,传统上替换为%20) 例如:www.MySite.com/Hello-World>www.MySite.com/Hello-World 到目前为止没有问题,我们只需向encodeNameReplacements添加另一个条目 <replace mode="on" find=" " replaceWith="-" /> 然后,为了防止内容作者创建名称中带有连字符的项目(
<replace mode="on" find=" " replaceWith="-" />
然后,为了防止内容作者创建名称中带有连字符的项目(Sitecore在读取其URL时会将其理解为有空格,导致找不到404),我们可以使用
<setting name="InvalidItemNameChars" value="\/:?"<>|[]-"/>
您可以编写一个类并将其放入web.config中的item saved事件中。只需编写onitemsave
方法,并让它检查名称中的连字符。我想你需要在重命名和复制时也这样做
<event name="item:saved">
<handler type="Sitecore.Links.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" />
<handler type="Sitecore.Tasks.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" />
<handler type="Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" />
<handler type="Sitecore.Rules.ItemEventHandler, Sitecore.Kernel" method="OnItemSaved" />
<handler type="YourAssembly.ItemEventHandler, YourAssembly" method="OnItemSaved" />
</event>
这将使用规则引擎替换特殊字符,例如项目名称中的空格:
如果在处理URL时没有替换,而只是翻译,Sitecore的项目解析器将尝试查找带有破折号而不是空格的项目名称,并且不会找到匹配的项目。如果没有实际替换字符,则需要重写项解析器
如果您想让名称中的空格对用户可见,但实际上是用破折号命名项目,那么您可以在将空格重命名为破折号时使用空格将项目的显示名称设置为原始值,但我建议您不要这样做。谢谢,这看起来非常适合我们。