V9: Visiting a page without a template returns "Page Not Found" (#11852)
* Returns "Page Not Found" when template doesn't exist for a docType * Fix comment * Use IsNullOrWhiteSpace instead of IsNullOrEmpty Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
This commit is contained in:
committed by
GitHub
parent
364b8f1c72
commit
1b5830a9d7
@@ -53,6 +53,26 @@ namespace Umbraco.Cms.Web.Common.Controllers
|
||||
/// </summary>
|
||||
public virtual IActionResult Index() => CurrentTemplate(new ContentModel(CurrentPage));
|
||||
|
||||
/// <summary>
|
||||
/// Gets an action result based on the template name found in the route values and a model.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the model.</typeparam>
|
||||
/// <param name="model">The model.</param>
|
||||
/// <returns>The action result.</returns>
|
||||
/// <remarks>
|
||||
/// If the template found in the route values doesn't physically exist, Umbraco not found result is returned.
|
||||
/// </remarks>
|
||||
protected override IActionResult CurrentTemplate<T>(T model)
|
||||
{
|
||||
if (EnsurePhsyicalViewExists(UmbracoRouteValues.TemplateName) == false)
|
||||
{
|
||||
// no physical template file was found
|
||||
return new PublishedContentNotFoundResult(UmbracoContext);
|
||||
}
|
||||
|
||||
return View(UmbracoRouteValues.TemplateName, model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Before the controller executes we will handle redirects and not founds
|
||||
/// </summary>
|
||||
@@ -123,6 +143,6 @@ namespace Umbraco.Cms.Web.Common.Controllers
|
||||
{
|
||||
return new PublishedContentNotFoundResult(UmbracoContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Umbraco.Cms.Web.Common.Controllers
|
||||
/// <param name="model">The model.</param>
|
||||
/// <returns>The action result.</returns>
|
||||
/// <exception cref="InvalidOperationException">If the template found in the route values doesn't physically exist and exception is thrown</exception>
|
||||
protected IActionResult CurrentTemplate<T>(T model)
|
||||
protected virtual IActionResult CurrentTemplate<T>(T model)
|
||||
{
|
||||
if (EnsurePhsyicalViewExists(UmbracoRouteValues.TemplateName) == false)
|
||||
{
|
||||
@@ -90,6 +90,13 @@ namespace Umbraco.Cms.Web.Common.Controllers
|
||||
/// <param name="template">The view name.</param>
|
||||
protected bool EnsurePhsyicalViewExists(string template)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(template))
|
||||
{
|
||||
string docTypeAlias = UmbracoRouteValues.PublishedRequest.PublishedContent.ContentType.Alias;
|
||||
_logger.LogWarning("No physical template file was found for document type with alias {Alias}", docTypeAlias);
|
||||
return false;
|
||||
}
|
||||
|
||||
ViewEngineResult result = _compositeViewEngine.FindView(ControllerContext, template, false);
|
||||
if (result.View != null)
|
||||
{
|
||||
@@ -99,6 +106,5 @@ namespace Umbraco.Cms.Web.Common.Controllers
|
||||
_logger.LogWarning("No physical template file was found for template {Template}", template);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user