* Run code cleanup * Run dotnet format * Start manual cleanup in Web.Common * Finish up manual cleanup * Fix tests * Fix up InMemoryModelFactory.cs * Inject proper macroRenderer * Update src/Umbraco.Web.Common/Filters/JsonDateTimeFormatAttribute.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Web.Common/Filters/ValidateUmbracoFormRouteStringAttribute.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix based on review Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System.Net;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Umbraco.Cms.Core.Routing;
|
|
using Umbraco.Cms.Core.Web;
|
|
|
|
namespace Umbraco.Cms.Web.Common.ActionsResults;
|
|
|
|
/// <summary>
|
|
/// Returns the Umbraco not found result
|
|
/// </summary>
|
|
public class PublishedContentNotFoundResult : IActionResult
|
|
{
|
|
private readonly string? _message;
|
|
private readonly IUmbracoContext _umbracoContext;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PublishedContentNotFoundResult" /> class.
|
|
/// </summary>
|
|
public PublishedContentNotFoundResult(IUmbracoContext umbracoContext, string? message = null)
|
|
{
|
|
_umbracoContext = umbracoContext;
|
|
_message = message;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task ExecuteResultAsync(ActionContext context)
|
|
{
|
|
HttpResponse response = context.HttpContext.Response;
|
|
|
|
response.Clear();
|
|
|
|
response.StatusCode = StatusCodes.Status404NotFound;
|
|
|
|
IPublishedRequest? frequest = _umbracoContext.PublishedRequest;
|
|
var reason = "Cannot render the page at URL '{0}'.";
|
|
if (frequest?.HasPublishedContent() == false)
|
|
{
|
|
reason = "No umbraco document matches the URL '{0}'.";
|
|
}
|
|
else if (frequest?.HasTemplate() == false)
|
|
{
|
|
reason = "No template exists to render the document at URL '{0}'.";
|
|
}
|
|
|
|
var viewResult = new ViewResult { ViewName = "~/umbraco/UmbracoWebsite/NotFound.cshtml" };
|
|
context.HttpContext.Items.Add(
|
|
"reason",
|
|
string.Format(reason, WebUtility.HtmlEncode(_umbracoContext.OriginalRequestUrl.PathAndQuery)));
|
|
context.HttpContext.Items.Add("message", _message);
|
|
|
|
await viewResult.ExecuteResultAsync(context);
|
|
}
|
|
}
|