using System.Web; using Umbraco.Web.Composing; namespace Umbraco.Web.Routing { /// /// Gets executed when no document can be found in Umbraco /// 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(); var frequest = Current.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}'."; response.Write("

Page not found

"); response.Write("

"); response.Write(string.Format(reason, HttpUtility.HtmlEncode(Current.UmbracoContext.OriginalRequestUrl.PathAndQuery))); response.Write("

"); if (string.IsNullOrWhiteSpace(_message) == false) response.Write("

" + _message + "

"); response.Write("

This page can be replaced with a custom 404. Check the documentation for Custom 404 Error Pages.

"); response.Write("

This page is intentionally left ugly ;-)

"); response.Write(""); } public bool IsReusable => false; } }