Implements: #U4-2342 - IRenderMvcController
This commit is contained in:
18
src/Umbraco.Web/Mvc/IRenderMvcController.cs
Normal file
18
src/Umbraco.Web/Mvc/IRenderMvcController.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Web.Models;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// The interface that must be implemented for a controller to be designated to execute for route hijacking
|
||||
/// </summary>
|
||||
public interface IRenderMvcController : IController
|
||||
{
|
||||
/// <summary>
|
||||
/// The default action to render the front-end view
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
ActionResult Index(RenderModel model);
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,8 @@ namespace Umbraco.Web.Mvc
|
||||
//now we need to check if it exists, if not we need to return the Index by default
|
||||
if (ad == null)
|
||||
{
|
||||
//check if the controller is an instance of RenderMvcController
|
||||
if (controllerContext.Controller is RenderMvcController)
|
||||
//check if the controller is an instance of IRenderMvcController
|
||||
if (controllerContext.Controller is IRenderMvcController)
|
||||
{
|
||||
return new ReflectedActionDescriptor(controllerContext.Controller.GetType().GetMethod("Index"), "Index", controllerDescriptor);
|
||||
}
|
||||
|
||||
@@ -54,12 +54,24 @@ namespace Umbraco.Web.Mvc
|
||||
/// The controller.
|
||||
/// </returns>
|
||||
/// <param name="requestContext">The request context.</param><param name="controllerName">The name of the controller.</param>
|
||||
/// <remarks>
|
||||
/// We always set the correct ActionInvoker on our custom created controller, this is very important for route hijacking!
|
||||
/// </remarks>
|
||||
public virtual IController CreateController(RequestContext requestContext, string controllerName)
|
||||
{
|
||||
Type controllerType = GetControllerType(requestContext, controllerName) ??
|
||||
_innerFactory.GetControllerType(requestContext, ControllerExtensions.GetControllerName(typeof(RenderMvcController)));
|
||||
|
||||
return _innerFactory.GetControllerInstance(requestContext, controllerType);
|
||||
var instance = _innerFactory.GetControllerInstance(requestContext, controllerType);
|
||||
|
||||
var controllerInstance = instance as Controller;
|
||||
if (controllerInstance != null)
|
||||
{
|
||||
//set the action invoker!
|
||||
controllerInstance.ActionInvoker = new RenderActionInvoker();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -11,8 +11,11 @@ using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
public class RenderMvcController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// The default controller that is executed for rendering MVC content in Umbraco
|
||||
/// </summary>
|
||||
public class RenderMvcController : Controller, IRenderMvcController
|
||||
{
|
||||
|
||||
public RenderMvcController()
|
||||
{
|
||||
|
||||
@@ -239,11 +239,11 @@ namespace Umbraco.Web.Mvc
|
||||
if (controller != null)
|
||||
{
|
||||
|
||||
//ensure the controller is of type 'RenderMvcController'
|
||||
if (controller is RenderMvcController)
|
||||
//ensure the controller is of type 'IRenderMvcController' and ControllerBase
|
||||
if (controller is IRenderMvcController && controller is ControllerBase)
|
||||
{
|
||||
//set the controller and name to the custom one
|
||||
def.Controller = (ControllerBase)controller;
|
||||
def.Controller = (ControllerBase)controller;
|
||||
def.ControllerName = ControllerExtensions.GetControllerName(controller.GetType());
|
||||
if (def.ControllerName != defaultControllerName)
|
||||
{
|
||||
@@ -253,10 +253,11 @@ namespace Umbraco.Web.Mvc
|
||||
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}'.",
|
||||
"The current Document Type {0} matches a locally declared controller of type {1}. Custom Controllers for Umbraco routing must implement '{2}' and inherit from '{3}'.",
|
||||
() => publishedContentRequest.PublishedContent.DocumentTypeAlias,
|
||||
() => controller.GetType().FullName,
|
||||
() => typeof(RenderMvcController).FullName);
|
||||
() => typeof(IRenderMvcController).FullName,
|
||||
() => typeof(ControllerBase).FullName);
|
||||
//exit as we cannnot route to the custom controller, just route to the standard one.
|
||||
return def;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ using System.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
//NOTE: We currently are not using this at all and should/could probably remove it!
|
||||
|
||||
/// <summary>
|
||||
/// Creates SurfaceControllers
|
||||
/// </summary>
|
||||
|
||||
@@ -279,6 +279,7 @@
|
||||
<Compile Include="Dictionary\UmbracoCultureDictionary.cs" />
|
||||
<Compile Include="Dictionary\UmbracoCultureDictionaryFactory.cs" />
|
||||
<Compile Include="Mvc\BackOfficeArea.cs" />
|
||||
<Compile Include="Mvc\IRenderMvcController.cs" />
|
||||
<Compile Include="Mvc\UmbracoAuthorizeAttribute.cs" />
|
||||
<Compile Include="Mvc\NotChildAction.cs" />
|
||||
<Compile Include="Mvc\UmbracoAuthorizedController.cs" />
|
||||
|
||||
Reference in New Issue
Block a user