From 02235dce44c2f2a74e5de1b793d02b9a8b92b4fa Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Thu, 5 Jun 2014 01:10:03 +0700 Subject: [PATCH] Fixes #316, security trimming not functioning with AttributeRouting and MVC 5.1.x. --- .../Security/AuthorizeAttributeAclModule.cs | 13 ++++++++++++- .../Web/Routing/RouteDataExtensions.cs | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs index 091bfcde..b57857ad 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Security/AuthorizeAttributeAclModule.cs @@ -213,7 +213,8 @@ protected virtual bool TryFindActionDescriptor(string actionName, ControllerCont actionDescriptor = null; try { - actionDescriptor = controllerDescriptor.FindAction(controllerContext, actionName); + var actionSelector = new ActionSelector(); + actionDescriptor = actionSelector.FindAction(controllerContext, controllerDescriptor, actionName); if (actionDescriptor != null) return true; } @@ -278,5 +279,15 @@ protected virtual bool TryCreateController(Type controllerType, out ControllerBa } #endregion + + private class ActionSelector + : AsyncControllerActionInvoker + { + // Needed because FindAction is protected, and we are changing it to be public + public new ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName) + { + return base.FindAction(controllerContext, controllerDescriptor, actionName); + } + } } } \ No newline at end of file diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Routing/RouteDataExtensions.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Routing/RouteDataExtensions.cs index b9c79d66..d89b4c2c 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Routing/RouteDataExtensions.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/Web/Routing/RouteDataExtensions.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Web.Routing; namespace MvcSiteMapProvider.Web.Routing @@ -20,6 +22,14 @@ public static string GetOptionalString(this RouteData routeData, string valueNam return value as string; } + if (routeData.Values.ContainsKey("MS_DirectRouteMatches")) + { + if (((IEnumerable)routeData.Values["MS_DirectRouteMatches"]).First().Values.TryGetValue(valueName, out value)) + { + return value as string; + } + } + return string.Empty; } @@ -36,6 +46,14 @@ public static string GetAreaName(this RouteData routeData) return value as string; } + if (routeData.Values.ContainsKey("MS_DirectRouteMatches")) + { + if (((IEnumerable)routeData.Values["MS_DirectRouteMatches"]).First().DataTokens.TryGetValue("area", out value)) + { + return value as string; + } + } + return string.Empty; } }