Splits up UmbracoRouteValueTransformer and trying to figure out this hijacked route conundrum with no template :(

This commit is contained in:
Shannon
2021-01-08 02:10:13 +11:00
parent 53bc92608a
commit bc6768101e
9 changed files with 351 additions and 167 deletions

View File

@@ -118,6 +118,15 @@ namespace Umbraco.Web.Common.Controllers
/// </summary>
public virtual IActionResult Index() => CurrentTemplate(new ContentModel(CurrentPage));
/// <summary>
/// The action that renders when there is no template assigned, templates are not disabled and there is no hijacked route
/// </summary>
/// <remarks>
/// This action renders even if there might be content found, but if there is no template assigned, templates are not disabled and there is no hijacked route
/// then we render the blank screen.
/// </remarks>
public IActionResult NoTemplate() => GetNoTemplateResult(UmbracoRouteValues.PublishedRequest);
/// <summary>
/// Before the controller executes we will handle redirects and not founds
/// </summary>
@@ -126,10 +135,10 @@ namespace Umbraco.Web.Common.Controllers
IPublishedRequest pcr = UmbracoRouteValues.PublishedRequest;
_logger.LogDebug(
"Response status: Redirect={Redirect}, Is404={Is404}, StatusCode={ResponseStatusCode}",
pcr.IsRedirect() ? (pcr.IsRedirectPermanent() ? "permanent" : "redirect") : "none",
pcr.Is404() ? "true" : "false",
pcr.ResponseStatusCode);
"Response status: Redirect={Redirect}, Is404={Is404}, StatusCode={ResponseStatusCode}",
pcr.IsRedirect() ? (pcr.IsRedirectPermanent() ? "permanent" : "redirect") : "none",
pcr.Is404() ? "true" : "false",
pcr.ResponseStatusCode);
UmbracoRouteResult routeStatus = pcr.GetRouteResult();
switch (routeStatus)
@@ -142,9 +151,8 @@ namespace Umbraco.Web.Common.Controllers
: Redirect(pcr.RedirectUrl);
break;
case UmbracoRouteResult.NotFound:
// set the redirect result and do not call next to short circuit
context.Result = new PublishedContentNotFoundResult(UmbracoContext);
context.Result = GetNoTemplateResult(pcr);
break;
case UmbracoRouteResult.Success:
default:
@@ -153,5 +161,28 @@ namespace Umbraco.Web.Common.Controllers
break;
}
}
private PublishedContentNotFoundResult GetNoTemplateResult(IPublishedRequest pcr)
{
// missing template, so we're in a 404 here
// so the content, if any, is a custom 404 page of some sort
if (!pcr.HasPublishedContent())
{
// means the builder could not find a proper document to handle 404
return new PublishedContentNotFoundResult(UmbracoContext);
}
else if (!pcr.HasTemplate())
{
// means the engine could find a proper document, but the document has no template
// at that point there isn't much we can do
return new PublishedContentNotFoundResult(
UmbracoContext,
"In addition, no template exists to render the custom 404.");
}
else
{
return new PublishedContentNotFoundResult(UmbracoContext);
}
}
}
}