Custom Url Provider to remove segment results in url collision errors
I am working through a fairly large upgrade at the moment and as part of this, there will be some content restructuring. The customer wants to retain the original urls for now but the original content has dropped one level deeper in the content hierarchy and so I've written a UrlProvider to remove the new segment of the url. The problem is that all nodes this gets applied to now have an error:
This document is published but its url would collide with content (error)
I can see no reason why there should be a collision since the content that was at the url is no longer there. Any ideas why this might be failing?
The UrlProvider is as follows:
public class MyUrlProvider : DefaultUrlProvider
{
public MyUrlProvider()
: base(UmbracoConfig.For.UmbracoSettings().RequestHandler)
{
}
public override string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{
// Take curent content item from cache by its id
var content = umbracoContext.ContentCache.GetById(id);
var route = umbracoContext.ContentCache.GetRouteById(id);
// Check if the content exists and it has alias companyItem
if (content != null && route.StartsWith("/segment-to-remove/"))
{
var segments = route.Split(new[] { '/'}, StringSplitOptions.RemoveEmptyEntries);
var newSegments = segments.Skip(1);
return string.Join("/", newSegments.ToArray()).EnsureStartsWith("/").EnsureEndsWith("/");
}
return null;
}
}
The error message is misleading in this instance as there was no url collision it's just that at the time of testing the ContentFinder had not been implemented and so Umbraco was unable to resolve the route to a valid piece of content. Having now implemented the ContentFinder the error has gone and the original urls are working as intended.
Custom Url Provider to remove segment results in url collision errors
I am working through a fairly large upgrade at the moment and as part of this, there will be some content restructuring. The customer wants to retain the original urls for now but the original content has dropped one level deeper in the content hierarchy and so I've written a UrlProvider to remove the new segment of the url. The problem is that all nodes this gets applied to now have an error:
I can see no reason why there should be a collision since the content that was at the url is no longer there. Any ideas why this might be failing?
The UrlProvider is as follows:
I've found the cause of this via another issue on the tracker…
URL collision with custom IUrlProvider and common URL prefixes
The error message is misleading in this instance as there was no url collision it's just that at the time of testing the ContentFinder had not been implemented and so Umbraco was unable to resolve the route to a valid piece of content. Having now implemented the ContentFinder the error has gone and the original urls are working as intended.
is working on a reply...