Moved the DocumentNotFoundHandler to diff namespace, created new NoTemplateHandler and updated the engine
to route to it when no template is selected and when there are no hijacked routes.
This commit is contained in:
@@ -63,48 +63,55 @@ namespace Umbraco.Web.Mvc
|
||||
/// <returns></returns>
|
||||
internal virtual RouteDefinition GetUmbracoRouteDefinition(RequestContext requestContext, DocumentRequest documentRequest)
|
||||
{
|
||||
var defaultControllerName = ControllerExtensions.GetControllerName<RenderMvcController>();
|
||||
//creates the default route definition which maps to the 'UmbracoController' controller
|
||||
var def = new RouteDefinition
|
||||
{
|
||||
ControllerName = ControllerExtensions.GetControllerName<RenderMvcController>(),
|
||||
ControllerName = defaultControllerName,
|
||||
Controller = new RenderMvcController(),
|
||||
DocumentRequest = documentRequest,
|
||||
ActionName = ((Route)requestContext.RouteData.Route).Defaults["action"].ToString()
|
||||
ActionName = ((Route)requestContext.RouteData.Route).Defaults["action"].ToString(),
|
||||
HasHijackedRoute = false
|
||||
};
|
||||
|
||||
//check that a template is defined)
|
||||
if (documentRequest.HasTemplate)
|
||||
//check if there's a custom controller assigned, base on the document type alias.
|
||||
var controller = _controllerFactory.CreateController(requestContext, documentRequest.Document.DocumentTypeAlias);
|
||||
|
||||
|
||||
//check if that controller exists
|
||||
if (controller != null)
|
||||
{
|
||||
|
||||
//check if there's a custom controller assigned, base on the document type alias.
|
||||
var controller = _controllerFactory.CreateController(requestContext, documentRequest.Document.DocumentTypeAlias);
|
||||
|
||||
|
||||
//check if that controller exists
|
||||
if (controller != null)
|
||||
//ensure the controller is of type 'RenderMvcController'
|
||||
if (controller is RenderMvcController)
|
||||
{
|
||||
|
||||
//ensure the controller is of type 'RenderMvcController'
|
||||
if (controller is RenderMvcController)
|
||||
//set the controller and name to the custom one
|
||||
def.Controller = (ControllerBase)controller;
|
||||
def.ControllerName = ControllerExtensions.GetControllerName(controller.GetType());
|
||||
if (def.ControllerName != defaultControllerName)
|
||||
{
|
||||
//set the controller and name to the custom one
|
||||
def.Controller = (ControllerBase)controller;
|
||||
def.ControllerName = ControllerExtensions.GetControllerName(controller.GetType());
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Warn<RenderRouteHandler>("The current Document Type {0} matches a locally declared controller of type {1}. Custom Controllers for Umbraco routing must inherit from '{2}'.", documentRequest.Document.DocumentTypeAlias, controller.GetType().FullName, typeof(RenderMvcController).FullName);
|
||||
//exit as we cannnot route to the custom controller, just route to the standard one.
|
||||
return def;
|
||||
def.HasHijackedRoute = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Warn<RenderRouteHandler>("The current Document Type {0} matches a locally declared controller of type {1}. Custom Controllers for Umbraco routing must inherit from '{2}'.", documentRequest.Document.DocumentTypeAlias, controller.GetType().FullName, typeof(RenderMvcController).FullName);
|
||||
//exit as we cannnot route to the custom controller, just route to the standard one.
|
||||
return def;
|
||||
}
|
||||
|
||||
//check that a template is defined), if it doesn't and there is a hijacked route it will just route
|
||||
// to the index Action
|
||||
if (documentRequest.HasTemplate)
|
||||
{
|
||||
//check if the custom controller has an action with the same name as the template name (we convert ToUmbracoAlias since the template name might have invalid chars).
|
||||
//NOTE: This also means that all custom actions MUST be PascalCase.. but that should be standard.
|
||||
var templateName = documentRequest.Template.Alias.Split('.')[0].ToUmbracoAlias(StringAliasCaseType.PascalCase);
|
||||
def.ActionName = templateName;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return def;
|
||||
}
|
||||
@@ -118,6 +125,13 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
var routeDef = GetUmbracoRouteDefinition(requestContext, documentRequest);
|
||||
|
||||
//here we need to check if there is no hijacked route and no template assigned, if this is the case
|
||||
//we want to return a blank page, but we'll leave that up to the NoTemplateHandler.
|
||||
if (!documentRequest.HasTemplate && !routeDef.HasHijackedRoute)
|
||||
{
|
||||
return new NoTemplateHandler();
|
||||
}
|
||||
|
||||
//no post values, just route to the controller/action requried (local)
|
||||
|
||||
requestContext.RouteData.Values["controller"] = routeDef.ControllerName;
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Represents the data required to route to a specific controller/action during an Umbraco request
|
||||
/// </summary>
|
||||
public class RouteDefinition
|
||||
internal class RouteDefinition
|
||||
{
|
||||
public string ControllerName { get; set; }
|
||||
public string ActionName { get; set; }
|
||||
@@ -19,5 +19,10 @@ namespace Umbraco.Web.Mvc
|
||||
/// The current RenderModel found for the request
|
||||
/// </summary>
|
||||
public object DocumentRequest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets whether the current request has a hijacked route/user controller routed for it
|
||||
/// </summary>
|
||||
public bool HasHijackedRoute { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web;
|
||||
|
||||
namespace Umbraco.Web
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets executed when no document can be found in Umbraco
|
||||
/// </summary>
|
||||
public class DocumentNotFoundHttpHandler : IHttpHandler
|
||||
internal class DocumentNotFoundHandler : IHttpHandler
|
||||
{
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
31
src/Umbraco.Web/Routing/NoTemplateHandler.cs
Normal file
31
src/Umbraco.Web/Routing/NoTemplateHandler.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Web;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets executed when there is no template assigned to a request and there is no hijacked MVC route
|
||||
/// </summary>
|
||||
internal class NoTemplateHandler : IHttpHandler
|
||||
{
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
WriteOutput(context);
|
||||
}
|
||||
|
||||
internal void WriteOutput(HttpContext context)
|
||||
{
|
||||
context.Response.Clear();
|
||||
context.Response.Write("");
|
||||
context.Response.End();
|
||||
}
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get
|
||||
{
|
||||
//yes this is reusable since it always returns the same thing
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,6 +260,7 @@
|
||||
<Compile Include="RenderFieldCaseType.cs" />
|
||||
<Compile Include="RenderFieldEncodingType.cs" />
|
||||
<Compile Include="Routing\LookupByPageIdQuery.cs" />
|
||||
<Compile Include="Routing\NoTemplateHandler.cs" />
|
||||
<Compile Include="umbraco.presentation\Default.aspx.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
@@ -270,7 +271,7 @@
|
||||
<Compile Include="ViewDataContainerExtensions.cs" />
|
||||
<Compile Include="XmlPublishedContentStore.cs" />
|
||||
<Compile Include="ContentStoreResolver.cs" />
|
||||
<Compile Include="DocumentNotFoundHttpHandler.cs" />
|
||||
<Compile Include="Routing\DocumentNotFoundHandler.cs" />
|
||||
<Compile Include="IPublishedContentStore.cs" />
|
||||
<Compile Include="Models\XmlDocument.cs" />
|
||||
<Compile Include="Models\XmlDocumentProperty.cs" />
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace Umbraco.Web
|
||||
//if no doc is found, send to our not found handler
|
||||
if (docreq.Is404)
|
||||
{
|
||||
httpContext.RemapHandler(new DocumentNotFoundHttpHandler());
|
||||
httpContext.RemapHandler(new DocumentNotFoundHandler());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace umbraco {
|
||||
/// <summary>
|
||||
/// Summary description for requestHandler.
|
||||
/// </summary>
|
||||
[Obsolete("This class is no longer used and will be removed in future versions")]
|
||||
public class requestHandler {
|
||||
#region public properties
|
||||
|
||||
|
||||
Reference in New Issue
Block a user