Added some code comments and did a check for redirects (returns null if this is the case)

This commit is contained in:
Shannon Deminick
2012-10-30 06:49:36 +06:00
parent 36eea348ba
commit c3795d7e5a
4 changed files with 22 additions and 3 deletions

View File

@@ -270,6 +270,12 @@ namespace Umbraco.Web.Mvc
if (!publishedContentRequest.HasTemplate && !routeDef.HasHijackedRoute)
{
var handler = publishedContentRequest.ProcessNoTemplateInMvc(requestContext.HttpContext);
//though this code should never execute if the ProcessNoTemplateInMvc method redirects, it seems that we should check it
//and return null, this could be required for unit testing as well
if (publishedContentRequest.IsRedirect)
{
return null;
}
// if it's not null it can be either the PublishedContentNotFoundHandler (no document was
// found to handle 404, or document with no template was found) or the WebForms handler

View File

@@ -32,7 +32,6 @@ namespace Umbraco.Web.Routing
/// </summary>
/// <param name="httpContext"></param>
/// <param name="umbracoContext"></param>
/// <param name="uri"></param>
/// <param name="onSuccess"></param>
internal void ProcessRequest(HttpContextBase httpContext, UmbracoContext umbracoContext, Action<PublishedContentRequest> onSuccess)
{
@@ -107,6 +106,13 @@ namespace Umbraco.Web.Routing
onSuccess(this);
}
/// <summary>
/// After execution is handed off to MVC, we can finally check if the request has: No Template assigned and also the
/// route is not hijacked. When this occurs, we need to send the routing back through the builder to check for
/// not found handlers.
/// </summary>
/// <param name="httpContext"></param>
/// <returns></returns>
internal IHttpHandler ProcessNoTemplateInMvc(HttpContextBase httpContext)
{
var content = this.PublishedContent;
@@ -117,7 +123,10 @@ namespace Umbraco.Web.Routing
// redirect if it has been flagged
if (this.IsRedirect)
{
httpContext.Response.Redirect(this.RedirectUrl, true);
}
// here .Is404 _has_ to be true
httpContext.Response.StatusCode = 404;

View File

@@ -174,7 +174,10 @@ namespace Umbraco.Web.Routing
/// <summary>
/// Performs the document resolution second pass.
/// </summary>
/// <remarks>The second pass consists in handling "not found", internal redirects, access validation, and template.</remarks>
/// <remarks>
/// The second pass consists in handling "not found", internal redirects, access validation, and template.
/// TODO: Rename this method accordingly .... but to what?
/// </remarks>
internal void LookupDocument2()
{
const string tracePrefix = "LookupDocument2: ";

View File

@@ -104,7 +104,8 @@ namespace Umbraco.Web
// instanciate a request a process
// important to use CleanedUmbracoUrl - lowercase path-only version of the current url
var docreq = new PublishedContentRequest(umbracoContext.CleanedUmbracoUrl, umbracoContext.RoutingContext);
docreq.ProcessRequest(httpContext, umbracoContext, docreq2 => RewriteToUmbracoHandler(HttpContext.Current, uri.Query, docreq2.RenderingEngine));
docreq.ProcessRequest(httpContext, umbracoContext,
docreq2 => RewriteToUmbracoHandler(HttpContext.Current, uri.Query, docreq2.RenderingEngine));
}
/// <summary>