using System.Web.Mvc; using System.Web.Routing; namespace Umbraco.Web.Mvc { /// /// A controller factory for the render pipeline of Umbraco. This controller factory tries to create a controller with the supplied /// name, and falls back to UmbracoController if none was found. /// /// public class RenderControllerFactory : UmbracoControllerFactory { /// /// Determines whether this instance can handle the specified request. /// /// The request. /// true if this instance can handle the specified request; otherwise, false. /// public override bool CanHandle(RequestContext request) { var dataToken = request.RouteData.DataTokens["area"]; return dataToken == null || string.IsNullOrWhiteSpace(dataToken.ToString()); } /// /// Creates the controller /// /// /// /// /// /// We always set the correct ActionInvoker on our custom created controller, this is very important for route hijacking! /// public override IController CreateController(RequestContext requestContext, string controllerName) { var instance = base.CreateController(requestContext, controllerName); var controllerInstance = instance as Controller; if (controllerInstance != null) { //set the action invoker! controllerInstance.ActionInvoker = new RenderActionInvoker(); } return instance; } } }