Skip to content

Commit

Permalink
Fixes #272, added an AclModule context to the request caching of the …
Browse files Browse the repository at this point in the history
…URL so it will still be possible to override route values when security trimming is enabled.
  • Loading branch information
NightOwl888 committed Oct 11, 2015
1 parent a4b8953 commit 71c7de9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/MvcSiteMapProvider/MvcSiteMapProvider/ISiteMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ public interface ISiteMap
[Obsolete("ResolveActionMethodParameters is deprecated and will be removed in version 5.")]
IEnumerable<string> ResolveActionMethodParameters(string areaName, string controllerName, string actionMethodName);
}

public static class SiteMapExtensions
{
public static string GetUrlContextKey(this ISiteMap siteMap)
{
return "__MVCSITEMAP_" + siteMap.CacheKey + "_UrlContext_" + siteMap.IsReadOnly.ToString() + "_";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ public override bool IsAccessibleToUser(ISiteMapNode node)
var result = this.requestCache.GetValue<bool?>(key);
if (result == null)
{
// Fix for #272 - Change the context of the URL cache to ensure
// that the AclModule doesn't prevent manually setting route values
// from having any effect on the URL. This setting takes effect in
// the RequestCacheableSiteMapNode.Url property.
var urlContextKey = this.GetUrlContextKey();
this.requestCache.SetValue<string>(urlContextKey, "AclModule");
result = base.IsAccessibleToUser(node);
this.requestCache.SetValue<bool>(key, (bool)result);

// Restore the URL context.
this.requestCache.SetValue<string>(urlContextKey, string.Empty);
}
return (bool)result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,16 @@ public override bool IsVisible(IDictionary<string, object> sourceMetadata)

public override string Url
{
get { return this.GetCachedOrMemberValue<string>(() => base.Url, "Url", true); }
get
{
// Fix for #272 - Change the context of the URL cache to ensure
// that the AclModule doesn't prevent manually setting route values
// from having any effect on the URL.
var urlContext = this.requestCache.GetValue<string>(this.SiteMap.GetUrlContextKey());
var memberName = "Url" + (string.IsNullOrEmpty(urlContext) ? string.Empty : "_" + urlContext);

return this.GetCachedOrMemberValue<string>(() => base.Url, memberName, true);
}
set { base.Url = value; }
}

Expand Down

0 comments on commit 71c7de9

Please sign in to comment.