From 3285e161c02afa269f692cedce09abec09f2d7a9 Mon Sep 17 00:00:00 2001 From: Steve Temple Date: Tue, 15 Oct 2013 17:09:51 +0100 Subject: [PATCH 1/5] Fix issue with error http://our.umbraco.org/forum/developers/api-questions/41483-Umbraco-6-MVC-RenderRouteHandlerHandlePostedValues-Sequence-contains-more-than-one-matching-element when multiple routes share the same controller --- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index 6756847980..b4c1f4b25d 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -200,6 +200,7 @@ namespace Umbraco.Web.Mvc .SingleOrDefault(x => x.Defaults != null && x.Defaults.ContainsKey("controller") && x.Defaults["controller"].ToString() == postedInfo.ControllerName && + x.Defaults["action"].ToString().ToLower() == postedInfo.ActionName.ToLower() && !x.DataTokens.ContainsKey("area")); } else From 4236473b14a69ce9fe46bb7405b2daa057a6daac Mon Sep 17 00:00:00 2001 From: Steve Temple Date: Tue, 15 Oct 2013 17:15:53 +0100 Subject: [PATCH 2/5] Tidied up tabs to match Umbraco standard --- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index b4c1f4b25d..4b0ed7db11 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -200,7 +200,7 @@ namespace Umbraco.Web.Mvc .SingleOrDefault(x => x.Defaults != null && x.Defaults.ContainsKey("controller") && x.Defaults["controller"].ToString() == postedInfo.ControllerName && - x.Defaults["action"].ToString().ToLower() == postedInfo.ActionName.ToLower() && + String.Equals(x.Defaults["action"].ToString(), postedInfo.ActionName, StringComparison.CurrentCultureIgnoreCase) && !x.DataTokens.ContainsKey("area")); } else From e06e50c4fce8875df0b70f5302ac289395ef3813 Mon Sep 17 00:00:00 2001 From: Steve Temple Date: Tue, 15 Oct 2013 17:15:53 +0100 Subject: [PATCH 3/5] Tidied up tabs to match Umbraco standard and nicer string comparison --- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index b4c1f4b25d..4b0ed7db11 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -200,7 +200,7 @@ namespace Umbraco.Web.Mvc .SingleOrDefault(x => x.Defaults != null && x.Defaults.ContainsKey("controller") && x.Defaults["controller"].ToString() == postedInfo.ControllerName && - x.Defaults["action"].ToString().ToLower() == postedInfo.ActionName.ToLower() && + String.Equals(x.Defaults["action"].ToString(), postedInfo.ActionName, StringComparison.CurrentCultureIgnoreCase) && !x.DataTokens.ContainsKey("area")); } else From f5029122258a27efb0ffa7d9590ac411a97ea7b2 Mon Sep 17 00:00:00 2001 From: Steve Temple Date: Tue, 15 Oct 2013 23:51:39 +0100 Subject: [PATCH 4/5] Updated to use invariant culture --- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index 4b0ed7db11..7f0c7bc3ce 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -198,10 +198,10 @@ namespace Umbraco.Web.Mvc //find the controller in the route table without an area surfaceRoute = RouteTable.Routes.OfType() .SingleOrDefault(x => x.Defaults != null && - x.Defaults.ContainsKey("controller") && - x.Defaults["controller"].ToString() == postedInfo.ControllerName && - String.Equals(x.Defaults["action"].ToString(), postedInfo.ActionName, StringComparison.CurrentCultureIgnoreCase) && - !x.DataTokens.ContainsKey("area")); + x.Defaults.ContainsKey("controller") && + x.Defaults["controller"].ToString() == postedInfo.ControllerName && + String.Equals(x.Defaults["action"].ToString(), postedInfo.ActionName, StringComparison.InvariantCultureIgnoreCase) && + !x.DataTokens.ContainsKey("area")); } else { From e738738e542190f03c12126abf2ec4cc56cc9108 Mon Sep 17 00:00:00 2001 From: Steve Temple Date: Wed, 16 Oct 2013 12:02:20 +0100 Subject: [PATCH 5/5] Only check actions if more than 1 route matches & ignore case when comparing controller names --- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index 7f0c7bc3ce..38d21d9577 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -195,15 +195,26 @@ namespace Umbraco.Web.Mvc Route surfaceRoute; if (postedInfo.Area.IsNullOrWhiteSpace()) { - //find the controller in the route table without an area - surfaceRoute = RouteTable.Routes.OfType() - .SingleOrDefault(x => x.Defaults != null && - x.Defaults.ContainsKey("controller") && - x.Defaults["controller"].ToString() == postedInfo.ControllerName && - String.Equals(x.Defaults["action"].ToString(), postedInfo.ActionName, StringComparison.InvariantCultureIgnoreCase) && - !x.DataTokens.ContainsKey("area")); + //find the controller in the route table without an area + var surfaceRoutes = RouteTable.Routes.OfType() + .Where(x => x.Defaults != null && + x.Defaults.ContainsKey("controller") && + String.Equals(x.Defaults["controller"].ToString(), postedInfo.ControllerName, StringComparison.InvariantCultureIgnoreCase) && + !x.DataTokens.ContainsKey("area")).ToList(); + + // If more than one route is found, find one with a matching action + if (surfaceRoutes.Count() > 1) + { + surfaceRoute = surfaceRoutes.SingleOrDefault(x => + String.Equals(x.Defaults["action"].ToString(), postedInfo.ActionName, StringComparison.InvariantCultureIgnoreCase)); + } + else + { + surfaceRoute = surfaceRoutes.SingleOrDefault(); + } + } - else + else { //find the controller in the route table with the specified area surfaceRoute = RouteTable.Routes.OfType()