Fixes cases where there are no domains assigned, ensures there can't be duplicate URLs returned to the UI
This commit is contained in:
@@ -104,8 +104,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// hideTopLevelNode = support legacy stuff, look for /*/path/to/node
|
||||
// else normal, look for /path/to/node
|
||||
content = hideTopLevelNode.Value
|
||||
? GetAtRoot(preview).SelectMany(x => x.Children).FirstOrDefault(x => x.UrlName == parts[0])
|
||||
: GetAtRoot(preview).FirstOrDefault(x => x.UrlName == parts[0]);
|
||||
? GetAtRoot(preview).SelectMany(x => x.Children).FirstOrDefault(x => x.GetUrlName(_localizationService, culture) == parts[0])
|
||||
: GetAtRoot(preview).FirstOrDefault(x => x.GetUrlName(_localizationService, culture) == parts[0]);
|
||||
content = FollowRoute(content, parts, 1, culture);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// have to look for /foo (see note in ApplyHideTopLevelNodeFromPath).
|
||||
if (content == null && hideTopLevelNode.Value && parts.Length == 1)
|
||||
{
|
||||
content = GetAtRoot(preview).FirstOrDefault(x => x.UrlName == parts[0]);
|
||||
content = GetAtRoot(preview).FirstOrDefault(x => x.GetUrlName(_localizationService, culture) == parts[0]);
|
||||
}
|
||||
|
||||
return content;
|
||||
|
||||
@@ -90,8 +90,12 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
if (domainUris == null)
|
||||
{
|
||||
var path = "/" + node.Value<string>(Constants.Conventions.Content.UrlAlias);
|
||||
var uri = new Uri(path, UriKind.Relative);
|
||||
var umbracoUrlName = node.Value<string>(Constants.Conventions.Content.UrlAlias);
|
||||
if (string.IsNullOrWhiteSpace(umbracoUrlName))
|
||||
return Enumerable.Empty<string>();
|
||||
|
||||
var path = "/" + umbracoUrlName;
|
||||
var uri = new Uri(path, UriKind.Relative);
|
||||
return new[] { UriUtility.UriFromUmbraco(uri, _globalSettings, _requestConfig).ToString() };
|
||||
}
|
||||
else
|
||||
@@ -107,7 +111,6 @@ namespace Umbraco.Web.Routing
|
||||
result.Add(UriUtility.UriFromUmbraco(uri, _globalSettings, _requestConfig).ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,23 +94,25 @@ namespace Umbraco.Web.Routing
|
||||
/// </remarks>
|
||||
public virtual IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
|
||||
{
|
||||
var node = umbracoContext.ContentCache.GetById(id);
|
||||
//get the invariant route for this item, this will give us the Id of it's domain node if one is assigned
|
||||
var invariantRoute = umbracoContext.ContentCache.GetRouteById(id);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(invariantRoute))
|
||||
{
|
||||
_logger.Debug<DefaultUrlProvider>(() => $"Couldn't find any page with nodeId={id}. This is most likely caused by the page not being published.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var domainHelper = umbracoContext.GetDomainHelper(_siteDomainHelper);
|
||||
|
||||
var n = node;
|
||||
var domainUris = domainHelper.DomainsForNode(n.Id, current, false);
|
||||
while (domainUris == null && n != null) // n is null at root
|
||||
{
|
||||
// move to parent node
|
||||
n = n.Parent;
|
||||
domainUris = n == null ? null : domainHelper.DomainsForNode(n.Id, current);
|
||||
}
|
||||
// extract domainUri and path
|
||||
// route is /<path> or <domainRootId>/<path>
|
||||
var pos = invariantRoute.IndexOf('/');
|
||||
var path = pos == 0 ? invariantRoute : invariantRoute.Substring(pos);
|
||||
var domainUris = pos == 0 ? null : domainHelper.DomainsForNode(int.Parse(invariantRoute.Substring(0, pos)), current);
|
||||
|
||||
if (domainUris == null)
|
||||
{
|
||||
//there are no domains, exit
|
||||
if (domainUris ==null)
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
var result = new List<string>();
|
||||
foreach (var d in domainUris)
|
||||
@@ -120,8 +122,8 @@ namespace Umbraco.Web.Routing
|
||||
if (route == null) continue;
|
||||
|
||||
//need to strip off the leading ID for the route if it exists (occurs if the route is for a node with a domain assigned)
|
||||
var pos = route.IndexOf('/');
|
||||
var path = pos == 0 ? route : route.Substring(pos);
|
||||
pos = route.IndexOf('/');
|
||||
path = pos == 0 ? route : route.Substring(pos);
|
||||
|
||||
var uri = new Uri(CombinePaths(d.Uri.GetLeftPart(UriPartial.Path), path));
|
||||
uri = UriUtility.UriFromUmbraco(uri, _globalSettings, _requestSettings);
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Web.Routing
|
||||
if (contentService == null) throw new ArgumentNullException(nameof(contentService));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
var urls = new List<string>();
|
||||
var urls = new HashSet<string>();
|
||||
|
||||
if (content.Published == false)
|
||||
{
|
||||
@@ -104,8 +104,11 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
else
|
||||
{
|
||||
urls.Add(url);
|
||||
urls.AddRange(urlProvider.GetOtherUrls(content.Id));
|
||||
urls.Add(url);
|
||||
foreach(var otherUrl in urlProvider.GetOtherUrls(content.Id))
|
||||
{
|
||||
urls.Add(otherUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
|
||||
Reference in New Issue
Block a user