cloudscribe/cloudscribe.Web.Navigation

TreeNode.FindByUrl Returning Early Incorrect Match

Closed this issue · 2 comments

mgbbs commented

If a navigation tree is built in such a way that a node's Url is fully contained within a prior node's Url, then the prior node will be returned as a match when using FindByUrl. This causes an issue with identifying the CurrentNode, and makes the wrong menu item "active" in a nav bar.

Problem line is on Line 40
if (n.Value.Url.IndexOf(urlToMatch, StringComparison.OrdinalIgnoreCase) >= 0)

Might be tricky to work around this when taking into account route values and different route formats. I think my personal workaround is going to be to implement a finder based purely on controller and action.

Example:
<NavNode key="Service" controller="About" action="Service" text="Service"></NavNode>
<NavNode key="Company" controller="About" action="Index" text="Company"></NavNode>

Notice that the Url for the first node would be /About/Service and the Url for the second node would be /About. If the current request path is /About, this would be matched to /About/Service and it would be incorrectly identified as the CurrentNode.

Are you sure you are using the latest version? This seems duplicate of #71
Note the code where nodes with controllers and actions specified is resolved is not at line 40, that would be used if you specify url in the xml.

mgbbs commented

Hi Joe and thanks for the quick reply. I was able to reproduce this problem in v2.1.17 and v2.1.20, so I updated the ticket you referenced. Apologies for opening a new one.

Line 40 I was referring to was TreeNodeExtensions.cs in the master branch. Closing this as duplicate.