diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index c30f83170b..64bdac669f 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -178,37 +178,28 @@ namespace Umbraco.Web.Mvc using (RouteTable.Routes.GetReadLock()) { Route surfaceRoute; - if (postedInfo.Area.IsNullOrWhiteSpace()) + + //find the controller in the route table + var surfaceRoutes = RouteTable.Routes.OfType() + .Where(x => x.Defaults != null && + x.Defaults.ContainsKey("controller") && + x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) && + // Only return surface controllers + x.DataTokens["umbraco"].ToString().InvariantEquals("surface") && + // Check for area token if the area is supplied + (postedInfo.Area.IsNullOrWhiteSpace() ? !x.DataTokens.ContainsKey("area") : x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area))) + .ToList(); + + // If more than one route is found, find one with a matching action + if (surfaceRoutes.Count > 1) { - //find the controller in the route table without an area - var surfaceRoutes = RouteTable.Routes.OfType() - .Where(x => x.Defaults != null && - x.Defaults.ContainsKey("controller") && - x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) && - x.DataTokens.ContainsKey("area") == false).ToList(); - - // If more than one route is found, find one with a matching action - if (surfaceRoutes.Count > 1) - { - surfaceRoute = surfaceRoutes.FirstOrDefault(x => - x.Defaults["action"] != null && - x.Defaults["action"].ToString().InvariantEquals(postedInfo.ActionName)); - } - else - { - surfaceRoute = surfaceRoutes.SingleOrDefault(); - } - + surfaceRoute = surfaceRoutes.FirstOrDefault(x => + x.Defaults["action"] != null && + x.Defaults["action"].ToString().InvariantEquals(postedInfo.ActionName)); } else { - //find the controller in the route table with the specified area - surfaceRoute = RouteTable.Routes.OfType() - .SingleOrDefault(x => x.Defaults != null && - x.Defaults.ContainsKey("controller") && - x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) && - x.DataTokens.ContainsKey("area") && - x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area)); + surfaceRoute = surfaceRoutes.FirstOrDefault(); } if (surfaceRoute == null)