如何将所有网址更改为大写/小写,或更改默认命名约定?
EG。从:
http://our.umbraco.org/projects/backoffice-extensions/
为:
http://our.umbraco.org/Projects/Backoffice-Extensions/
答案 0 :(得分:2)
如果你知道如何编程C#,那就不那么难了。
您基本上需要编写自己的UrlSegmentProvider (see documentation)。
public class UppercaseUrlSegmentProvider: IUrlSegmentProvider
{
private readonly IUrlSegmentProvider provider = new DefaultUrlSegmentProvider();
public string GetUrlSegment(IContentBase content)
{
return this.GetUrlSegment(content, CultureInfo.CurrentCulture);
}
public string GetUrlSegment(IContentBase content, CultureInfo culture)
{
// Maybe you don't want to do that for all contentTypes
// if so, check on the contentType: if (content.ContentTypeId != 1086)
var segment = this.provider.GetUrlSegment(content);
// for the sake of simplicity I have put everything in uppercase,
// you could of course implement something like this:
// http://www.java2s.com/Code/CSharp/Data-Types/CamelCase.htm
return segment.ToUpper().ToUrlSegment();
}
}
要激活细分提供程序,您可以使用ApplicationEventHandler的ApplicationStarting方法。
public class MySegmentEvents : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
base.ApplicationStarting(umbracoApplication, applicationContext);
// UrlSegmentProviderResolver.Current.Clear();
UrlSegmentProviderResolver.Current.InsertType<UppercaseUrlSegmentProvider>(0);
}
}
注意,如果您已实现上述代码,则现有节点不会自动更改。只有在“保存并发布”之后,您的特定节点的URL才会拥有新的“细分”。