Skip to content

Commit

Permalink
Fixes #316, security trimming not functioning with AttributeRouting a…
Browse files Browse the repository at this point in the history
…nd MVC 5.1.x.
  • Loading branch information
NightOwl888 committed Jun 4, 2014
1 parent 3fa630e commit 02235dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;

namespace MvcSiteMapProvider.Web.Routing
Expand All @@ -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>)routeData.Values["MS_DirectRouteMatches"]).First().Values.TryGetValue(valueName, out value))
{
return value as string;
}
}

return string.Empty;
}

Expand All @@ -36,6 +46,14 @@ public static string GetAreaName(this RouteData routeData)
return value as string;
}

if (routeData.Values.ContainsKey("MS_DirectRouteMatches"))
{
if (((IEnumerable<RouteData>)routeData.Values["MS_DirectRouteMatches"]).First().DataTokens.TryGetValue("area", out value))
{
return value as string;
}
}

return string.Empty;
}
}
Expand Down

0 comments on commit 02235dc

Please sign in to comment.