Files
Umbraco-CMS/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs

53 lines
2.0 KiB
C#
Raw Normal View History

2018-06-29 19:52:40 +02:00
using System.Web;
2019-02-14 09:49:45 +01:00
using Umbraco.Web.Composing;
2018-06-29 19:52:40 +02:00
namespace Umbraco.Web.Routing
{
/// <summary>
/// Gets executed when no document can be found in Umbraco
/// </summary>
internal class PublishedContentNotFoundHandler : IHttpHandler
{
private readonly string _message;
public PublishedContentNotFoundHandler()
{ }
public PublishedContentNotFoundHandler(string message)
{
_message = message;
}
public void ProcessRequest(HttpContext context)
{
WriteOutput(context);
}
internal void WriteOutput(HttpContext context)
{
var response = context.Response;
response.Clear();
2019-02-14 09:49:45 +01:00
var frequest = Current.UmbracoContext.PublishedRequest;
2020-10-05 20:48:38 +02:00
var reason = "Cannot render the page at URL '{0}'.";
2018-06-29 19:52:40 +02:00
if (frequest.HasPublishedContent == false)
2020-10-05 20:48:38 +02:00
reason = "No umbraco document matches the URL '{0}'.";
2018-06-29 19:52:40 +02:00
else if (frequest.HasTemplate == false)
2020-10-05 20:48:38 +02:00
reason = "No template exists to render the document at URL '{0}'.";
2018-06-29 19:52:40 +02:00
response.Write("<html><body><h1>Page not found</h1>");
2020-03-06 18:04:01 +01:00
response.Write("<h2>");
2019-02-14 09:49:45 +01:00
response.Write(string.Format(reason, HttpUtility.HtmlEncode(Current.UmbracoContext.OriginalRequestUrl.PathAndQuery)));
2020-03-06 18:04:01 +01:00
response.Write("</h2>");
2018-06-29 19:52:40 +02:00
if (string.IsNullOrWhiteSpace(_message) == false)
response.Write("<p>" + _message + "</p>");
response.Write("<p>This page can be replaced with a custom 404. Check the documentation for <a href=\"https://our.umbraco.com/Documentation/Tutorials/Custom-Error-Pages/#404-errors\" target=\"_blank\">Custom 404 Error Pages</a>.</p>");
2018-06-29 19:52:40 +02:00
response.Write("<p style=\"border-top: 1px solid #ccc; padding-top: 10px\"><small>This page is intentionally left ugly ;-)</small></p>");
response.Write("</body></html>");
}
public bool IsReusable => false;
}
}