Changed back office routes to use a proper MVC area and ensures that the controller creations for all controllers are limited
to ONLY look in the namespaces declared for them, this will increase performance and ensure there's not conflicting controller creation... need to back port this to 6.0.x
This commit is contained in:
@@ -86,6 +86,9 @@ 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
|
||||
controllerPluginRoute.Constraints = new RouteValueDictionary(
|
||||
new Dictionary<string, object>
|
||||
|
||||
52
src/Umbraco.Web/Mvc/BackOfficeArea.cs
Normal file
52
src/Umbraco.Web/Mvc/BackOfficeArea.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Install;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// An area registration for back office components
|
||||
/// </summary>
|
||||
internal class BackOfficeArea : AreaRegistration
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Create the routes for the area
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
public override void RegisterArea(AreaRegistrationContext context)
|
||||
{
|
||||
//Default back office route
|
||||
context.MapRoute(
|
||||
"Umbraco_back_office",
|
||||
GlobalSettings.UmbracoMvcArea + "/{action}/{id}",
|
||||
new {controller = "BackOffice", action = "Default", id = UrlParameter.Optional},
|
||||
new[] {typeof (BackOfficeController).Namespace});
|
||||
|
||||
//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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,6 +297,7 @@
|
||||
<Compile Include="Models\ContentEditing\Tab.cs" />
|
||||
<Compile Include="Models\Mapping\ContentModelMapper.cs" />
|
||||
<Compile Include="FormDataCollectionExtensions.cs" />
|
||||
<Compile Include="Mvc\BackOfficeArea.cs" />
|
||||
<Compile Include="Trees\LegacyTreeApiController.cs" />
|
||||
<Compile Include="Trees\ISearchableTree.cs" />
|
||||
<Compile Include="Trees\LegacyTreeDataAdapter.cs" />
|
||||
|
||||
@@ -147,19 +147,7 @@ namespace Umbraco.Web
|
||||
protected internal void CreateRoutes()
|
||||
{
|
||||
var umbracoPath = GlobalSettings.UmbracoMvcArea;
|
||||
|
||||
//TODO: We should probably create a 'real' Umbraco area
|
||||
|
||||
//Create the back office route
|
||||
// TODO: Change this to the normal route, currently it is /Belle for dev testing
|
||||
var backOfficeRoute = RouteTable.Routes.MapRoute(
|
||||
"Umbraco_back_office",
|
||||
//umbracoPath + "/{action}/{id}",
|
||||
"Belle/{action}/{id}",
|
||||
new { controller = "BackOffice", action = "Default", id = UrlParameter.Optional },
|
||||
new[] { typeof(BackOfficeController).Namespace });
|
||||
backOfficeRoute.DataTokens.Add("area", umbracoPath);
|
||||
|
||||
|
||||
//Create the front-end route
|
||||
var defaultRoute = RouteTable.Routes.MapRoute(
|
||||
"Umbraco_default",
|
||||
@@ -168,27 +156,17 @@ 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);
|
||||
//register all back office routes
|
||||
RouteBackOfficeControllers();
|
||||
|
||||
//plugin controllers must come first because the next route will catch many things
|
||||
RoutePluginControllers();
|
||||
}
|
||||
|
||||
//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);
|
||||
|
||||
private void RouteBackOfficeControllers()
|
||||
{
|
||||
var backOfficeArea = new BackOfficeArea();
|
||||
RouteTable.Routes.RegisterArea(backOfficeArea);
|
||||
}
|
||||
|
||||
private void RoutePluginControllers()
|
||||
@@ -241,6 +219,7 @@ namespace Umbraco.Web
|
||||
route.DataTokens = new RouteValueDictionary();
|
||||
}
|
||||
route.DataTokens.Add("Namespaces", new[] {meta.ControllerNamespace}); //look in this namespace to create the controller
|
||||
route.DataTokens.Add("UseNamespaceFallback", false); //Don't look anywhere else except this namespace!
|
||||
route.DataTokens.Add("umbraco", "api"); //ensure the umbraco token is set
|
||||
}
|
||||
|
||||
@@ -255,6 +234,7 @@ namespace Umbraco.Web
|
||||
// 4.10 release so we can't include it now :(
|
||||
new[] { meta.ControllerNamespace }); //look in this namespace to create the controller
|
||||
route.DataTokens.Add("umbraco", "surface"); //ensure the umbraco token is set
|
||||
route.DataTokens.Add("UseNamespaceFallback", false); //Don't look anywhere else except this namespace!
|
||||
//make it use our custom/special SurfaceMvcHandler
|
||||
route.RouteHandler = new SurfaceRouteHandler();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user