Skip to content

Commit

Permalink
#10354 - added domain content id as node context for the content find…
Browse files Browse the repository at this point in the history
…er for the 404 error page so $site works
  • Loading branch information
kmeilander authored and nul800sebastiaan committed Aug 6, 2021
1 parent 0bc9f3e commit 1dd75b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ public bool TryFindContent(PublishedRequest frequest)
{
_logger.Debug<ContentFinderByConfigured404>("Looking for a page to handle 404.");

int? domainConentId = null;

// try to find a culture as best as we can
var errorCulture = CultureInfo.CurrentUICulture;
if (frequest.HasDomain)
{
errorCulture = frequest.Domain.Culture;
domainConentId = frequest.Domain.ContentId;
}
else
{
Expand All @@ -63,7 +66,9 @@ public bool TryFindContent(PublishedRequest frequest)
_contentConfigSection.Error404Collection.ToArray(),
_entityService,
new PublishedContentQuery(frequest.UmbracoContext.PublishedSnapshot, frequest.UmbracoContext.VariationContextAccessor),
errorCulture);
errorCulture,
domainConentId
);

IPublishedContent content = null;

Expand Down
11 changes: 6 additions & 5 deletions src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ internal class NotFoundHandlerHelper
IContentErrorPage[] error404Collection,
IEntityService entityService,
IPublishedContentQuery publishedContentQuery,
CultureInfo errorCulture)
CultureInfo errorCulture,
int? domainContentId)
{
if (error404Collection.Length > 1)
{
Expand All @@ -50,11 +51,11 @@ internal class NotFoundHandlerHelper
?? error404Collection.FirstOrDefault(x => x.Culture == "default"); // there should be a default one!

if (cultureErr != null)
return GetContentIdFromErrorPageConfig(cultureErr, entityService, publishedContentQuery);
return GetContentIdFromErrorPageConfig(cultureErr, entityService, publishedContentQuery, domainContentId);
}
else
{
return GetContentIdFromErrorPageConfig(error404Collection.First(), entityService, publishedContentQuery);
return GetContentIdFromErrorPageConfig(error404Collection.First(), entityService, publishedContentQuery, domainContentId);
}

return null;
Expand All @@ -67,7 +68,7 @@ internal class NotFoundHandlerHelper
/// <param name="entityService"></param>
/// <param name="publishedContentQuery"></param>
/// <returns></returns>
internal static int? GetContentIdFromErrorPageConfig(IContentErrorPage errorPage, IEntityService entityService, IPublishedContentQuery publishedContentQuery)
internal static int? GetContentIdFromErrorPageConfig(IContentErrorPage errorPage, IEntityService entityService, IPublishedContentQuery publishedContentQuery, int? domainContentId)
{
if (errorPage.HasContentId) return errorPage.ContentId;

Expand All @@ -92,7 +93,7 @@ internal class NotFoundHandlerHelper
//we have an xpath statement to execute
var xpathResult = UmbracoXPathPathSyntaxParser.ParseXPathQuery(
xpathExpression: errorPage.ContentXPath,
nodeContextId: null,
nodeContextId: domainContentId,
getPath: nodeid =>
{
var ent = entityService.Get(nodeid);
Expand Down

0 comments on commit 1dd75b9

Please sign in to comment.