diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index e418c0cb16..833fe92906 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.Mvc bool isMvc = true) { Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); - Mandate.ParameterNotNullOrEmpty(controllerSuffixName, "controllerSuffixName"); + Mandate.ParameterNotNull(controllerSuffixName, "controllerSuffixName"); Mandate.ParameterNotNull(controllerType, "controllerType"); Mandate.ParameterNotNull(routes, "routes"); @@ -86,13 +86,18 @@ namespace Umbraco.Web.Mvc controllerPluginRoute.DataTokens.Add("Namespaces", new[] {controllerType.Namespace}); } + //Don't look anywhere else except this namespace! + controllerPluginRoute.DataTokens.Add("UseNamespaceFallback", false); + //constraints: only match controllers ending with 'controllerSuffixName' and only match this controller's ID for this route + if (controllerSuffixName.IsNullOrWhiteSpace() == false) + { controllerPluginRoute.Constraints = new RouteValueDictionary( new Dictionary { {"controller", @"(\w+)" + controllerSuffixName} }); - + } //match this area controllerPluginRoute.DataTokens.Add("area", area.AreaName); diff --git a/src/Umbraco.Web/Mvc/BackOfficeArea.cs b/src/Umbraco.Web/Mvc/BackOfficeArea.cs new file mode 100644 index 0000000000..5393996d78 --- /dev/null +++ b/src/Umbraco.Web/Mvc/BackOfficeArea.cs @@ -0,0 +1,44 @@ +using System.Web.Mvc; +using Umbraco.Core.Configuration; +using Umbraco.Web.Install; + +namespace Umbraco.Web.Mvc +{ + /// + /// An area registration for back office components + /// + internal class BackOfficeArea : AreaRegistration + { + + /// + /// Create the routes for the area + /// + /// + /// + /// By using the context to register the routes it means that the area is already applied to them all + /// and that the namespaces searched for the controllers are ONLY the ones specified. + /// + public override void RegisterArea(AreaRegistrationContext context) + { + //Create the install routes + context.MapRoute( + "Umbraco_install_packages", + "Install/PackageInstaller/{action}/{id}", + new {controller = "InstallPackage", action = "Index", id = UrlParameter.Optional}, + new[] {typeof (InstallPackageController).Namespace}); + + //Create the REST/web/script service routes + context.MapRoute( + "Umbraco_web_services", + GlobalSettings.UmbracoMvcArea + "/RestServices/{controller}/{action}/{id}", + new {controller = "SaveFileController", action = "Index", id = UrlParameter.Optional}, + //look in this namespace for controllers + new[] {"Umbraco.Web.WebServices"}); + } + + public override string AreaName + { + get { return GlobalSettings.UmbracoMvcArea; } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 65f8c14d23..1149d70772 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -355,6 +355,7 @@ + diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 5f376a6e88..a796b70e62 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -39,10 +39,10 @@ namespace Umbraco.Web { private readonly bool _isForTesting; - public WebBootManager(UmbracoApplicationBase umbracoApplication) + public WebBootManager(UmbracoApplicationBase umbracoApplication) : this(umbracoApplication, false) { - + } /// @@ -50,10 +50,10 @@ namespace Umbraco.Web /// /// /// - internal WebBootManager(UmbracoApplicationBase umbracoApplication, bool isForTesting) + internal WebBootManager(UmbracoApplicationBase umbracoApplication, bool isForTesting) : base(umbracoApplication) { - _isForTesting = isForTesting; + _isForTesting = isForTesting; } /// @@ -61,7 +61,7 @@ namespace Umbraco.Web /// /// public override IBootManager Initialize() - { + { base.Initialize(); // Backwards compatibility - set the path and URL type for ClientDependency 1.5.1 [LK] @@ -155,26 +155,18 @@ namespace Umbraco.Web ); defaultRoute.RouteHandler = new RenderRouteHandler(ControllerBuilder.Current.GetControllerFactory()); - //Create the install routes - var installPackageRoute = RouteTable.Routes.MapRoute( - "Umbraco_install_packages", - "Install/PackageInstaller/{action}/{id}", - new { controller = "InstallPackage", action = "Index", id = UrlParameter.Optional } - ); - installPackageRoute.DataTokens.Add("area", umbracoPath); - - //Create the REST/web/script service routes - var webServiceRoutes = RouteTable.Routes.MapRoute( - "Umbraco_web_services", - umbracoPath + "/RestServices/{controller}/{action}/{id}", - new { controller = "SaveFileController", action = "Index", id = UrlParameter.Optional }, - //look in this namespace for controllers - new string[] { "Umbraco.Web.WebServices" } - ); - webServiceRoutes.DataTokens.Add("area", umbracoPath); + //register all back office routes + RouteBackOfficeControllers(); + //plugin controllers must come first because the next route will catch many things RoutePluginControllers(); } + + private void RouteBackOfficeControllers() + { + var backOfficeArea = new BackOfficeArea(); + RouteTable.Routes.RegisterArea(backOfficeArea); + } private void RoutePluginControllers() { @@ -228,7 +220,6 @@ namespace Umbraco.Web route.DataTokens.Add("Namespaces", new[] {meta.ControllerNamespace}); //look in this namespace to create the controller route.DataTokens.Add("umbraco", "api"); //ensure the umbraco token is set } - private void RouteLocalSurfaceController(Type controller, string umbracoPath) { var meta = PluginController.GetMetadata(controller);