Files
Umbraco-CMS/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs
T
Shannon Deminick 07f8f79620 Fixes: #U4-1077, found an bug with both our code and Microsoft's code in that if you RemapPath with an incorrect URL which contains
2 '?' the internals of ASP.net actually force a secondary internal request which causes BeginRequest to fire but doesn't follow the normal
chain of the module. It was a bug with our code having two query strings, however its pretty strange behavior on their part!
Have removed UmbracoContext.ClientUrl since it is not necessary to have. Have renamed UmbracoContext.UmbracoUrl = CleanedUmbracoUrl and UmbracoContext.RequextUrl = OriginalRequestUrl
Have moved the route processing logic to a static method on PublishedContentRequest which auto assigns the request back to the UmbracoContext, plus this is a cleaner
way to do the processing, including allowing us to unit test this one aspect.
Lastly, we are now rewriting the path back to the original URL in the RenderRouteHandler so that in MVC controllers the HttpContext.Request actually
reflects the URL that the client requested, not the rewritten URL (we do this in webforms too)
2012-10-26 02:55:57 +05:00

45 lines
1.3 KiB
C#

using System.Web;
namespace Umbraco.Web.Routing
{
/// <summary>
/// Gets executed when no document can be found in Umbraco
/// </summary>
internal class PublishedContentNotFoundHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
WriteOutput(context);
}
internal void WriteOutput(HttpContext context)
{
var response = context.Response;
response.Clear();
var docreq = UmbracoContext.Current.PublishedContentRequest;
var reason = "Cannot render the page at url '{0}'.";
if (!docreq.HasNode)
reason = "No umbraco document matches the url '{0}'.";
else if (!docreq.HasTemplate)
reason = "No template exists to render the document at url '{0}'.";
response.Write("<html><body><h1>Page not found</h1>");
response.Write("<h3>");
response.Write(string.Format(reason, HttpUtility.HtmlEncode(UmbracoContext.Current.OriginalRequestUrl)));
response.Write("</h3");
response.Write("<p>This page can be replaced with a custom 404. Check the documentation for \"custom 404\".</p>");
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>");
response.End();
}
public bool IsReusable
{
get { return true; }
}
}
}