diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs
index 5bdd0bac75..b52a560d47 100644
--- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs
+++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs
@@ -74,7 +74,9 @@ namespace Umbraco.Tests.Routing
handler.GetHandlerForRoute(routingContext.UmbracoContext.HttpContext.Request.RequestContext, docRequest);
Assert.AreEqual("RenderMvc", routeData.Values["controller"].ToString());
- Assert.AreEqual("Index", routeData.Values["action"].ToString());
+ //the route action will still be the one we've asked for because our RenderActionInvoker is the thing that decides
+ // if the action matches.
+ Assert.AreEqual("homePage", routeData.Values["action"].ToString());
}
//test all template name styles to match the ActionName
diff --git a/src/Umbraco.Tests/Stubs/TestControllerFactory.cs b/src/Umbraco.Tests/Stubs/TestControllerFactory.cs
index 98bedaa078..872093f896 100644
--- a/src/Umbraco.Tests/Stubs/TestControllerFactory.cs
+++ b/src/Umbraco.Tests/Stubs/TestControllerFactory.cs
@@ -3,6 +3,7 @@ using System.Linq;
using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
+using System.Web.SessionState;
using Umbraco.Core;
namespace Umbraco.Tests.Stubs
@@ -28,12 +29,12 @@ namespace Umbraco.Tests.Stubs
public System.Web.SessionState.SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
{
- throw new NotImplementedException();
+ return SessionStateBehavior.Disabled;
}
public void ReleaseController(IController controller)
{
- throw new NotImplementedException();
+ controller.DisposeIfDisposable();
}
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Mvc/ControllerFactoryExtensions.cs b/src/Umbraco.Web/Mvc/ControllerFactoryExtensions.cs
new file mode 100644
index 0000000000..86f24ac452
--- /dev/null
+++ b/src/Umbraco.Web/Mvc/ControllerFactoryExtensions.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Web.Mvc;
+using System.Web.Routing;
+
+namespace Umbraco.Web.Mvc
+{
+ internal static class ControllerFactoryExtensions
+ {
+ ///
+ /// Gets a controller type by the name
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// This is related to issue: http://issues.umbraco.org/issue/U4-1726. We already have a method called GetControllerTypeInternal on our MasterControlelrFactory,
+ /// however, we cannot always guarantee that the usage of this will be a MasterControllerFactory like during unit tests. So we needed to create
+ /// this extension method to do the checks instead.
+ ///
+ internal static Type GetControllerTypeInternal(this IControllerFactory factory, RequestContext requestContext, string controllerName)
+ {
+ var controllerFactory = factory as MasterControllerFactory;
+ if (controllerFactory != null)
+ {
+ return controllerFactory.GetControllerTypeInternal(requestContext, controllerName);
+ }
+
+ //we have no choice but to instantiate the controller
+ var instance = factory.CreateController(requestContext, controllerName);
+ if (instance != null)
+ {
+ return instance.GetType();
+ }
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Mvc/MasterControllerFactory.cs b/src/Umbraco.Web/Mvc/MasterControllerFactory.cs
index 4a58fb7251..100b192bf8 100644
--- a/src/Umbraco.Web/Mvc/MasterControllerFactory.cs
+++ b/src/Umbraco.Web/Mvc/MasterControllerFactory.cs
@@ -9,7 +9,7 @@ using Umbraco.Core;
namespace Umbraco.Web.Mvc
{
- ///
+ ///
/// A controller factory which uses an internal list of in order to invoke
/// different controller factories dependent upon their implementation of for the current
/// request. Allows circumvention of MVC3's singly registered IControllerFactory.
@@ -70,7 +70,11 @@ namespace Umbraco.Web.Mvc
}
//we have no choice but to instantiate the controller
var instance = factory.CreateController(requestContext, controllerName);
- return instance.GetType();
+ if (instance != null)
+ {
+ return instance.GetType();
+ }
+ return null;
}
return base.GetControllerType(requestContext, controllerName);
diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs
index c7ab7a9ee0..5569fa9a92 100644
--- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs
+++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs
@@ -259,7 +259,7 @@ namespace Umbraco.Web.Mvc
}
//check if there's a custom controller assigned, base on the document type alias.
- var controllerType = ((MasterControllerFactory)_controllerFactory).GetControllerTypeInternal(requestContext, publishedContentRequest.PublishedContent.DocumentTypeAlias);
+ var controllerType = _controllerFactory.GetControllerTypeInternal(requestContext, publishedContentRequest.PublishedContent.DocumentTypeAlias);
//check if that controller exists
if (controllerType != null)
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 22238d67e7..5c3682e108 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -300,6 +300,7 @@
+