Skip to content

Commit

Permalink
Fixes #322, using custom URL resolver throws "multiple nodes with sam…
Browse files Browse the repository at this point in the history
…e URL" exception.
  • Loading branch information
NightOwl888 committed Jun 10, 2014
1 parent bdbd74b commit bc43bf9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using MvcSiteMapProvider.Web.UrlResolver;

namespace MvcSiteMapProvider
{
/// <summary>
/// Contains extension logic for the ISiteMapNode interface that is not user
/// overridable.
/// </summary>
public static class ISiteMapNodeExtensions
{
public static bool UsesDefaultUrlResolver(this ISiteMapNode node)
{
return string.IsNullOrEmpty(node.UrlResolver) ||
typeof(SiteMapNodeUrlResolver).Equals(Type.GetType(node.UrlResolver, false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ IUrlPath urlPath

// Host name in absolute URL overrides this one.
this.hostName = node.HostName;
this.SetUrlValues(node.UnresolvedUrl);

// Fixes #322 - If using a custom URL resolver, we need to account for the case that
// the URL will be provided by the resolver instead of specified explicitly.
if (!string.IsNullOrEmpty(node.UnresolvedUrl))
{
this.SetUrlValues(node.UnresolvedUrl);
}
else if (!node.UsesDefaultUrlResolver())
{
// For a custom URL resolver, if the unresolved URL property
// is not set use the one returned from the URL resolver.
// This ensures URLs that are unidentifiable by MVC can still
// be matched by URL.
this.SetUrlValues(node.Url);
}
}

private readonly ISiteMapNode node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<Compile Include="Globalization\CultureContextFactory.cs" />
<Compile Include="Globalization\ICultureContextFactory.cs" />
<Compile Include="Globalization\ICultureContext.cs" />
<Compile Include="ISiteMapNodeExtensions.cs" />
<Compile Include="ISiteMapNodeProvider.cs" />
<Compile Include="ISiteMapSettings.cs" />
<Compile Include="ISortable.cs" />
Expand Down
8 changes: 1 addition & 7 deletions src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected virtual void AddNodeInternal(ISiteMapNode node, ISiteMapNode parentNod
lock (this.synclock)
{
IUrlKey url = null;
bool isMvcUrl = string.IsNullOrEmpty(node.UnresolvedUrl) && this.UsesDefaultUrlResolver(node);
bool isMvcUrl = string.IsNullOrEmpty(node.UnresolvedUrl) && node.UsesDefaultUrlResolver();

// Only store URLs if they are clickable and are configured using the Url
// property or provided by a custom URL resolver.
Expand Down Expand Up @@ -816,12 +816,6 @@ protected virtual ISiteMapNode ReturnNodeIfAccessible(ISiteMapNode node)
return null;
}

protected virtual bool UsesDefaultUrlResolver(ISiteMapNode node)
{
return string.IsNullOrEmpty(node.UrlResolver) ||
typeof(MvcSiteMapProvider.Web.UrlResolver.SiteMapNodeUrlResolver).Equals(Type.GetType(node.UrlResolver, false));
}

protected virtual void AssertSiteMapNodeConfigurationIsValid(ISiteMapNode node)
{
ThrowIfTitleNotSet(node);
Expand Down

0 comments on commit bc43bf9

Please sign in to comment.