Trailing slash on url causes SiteMapProvider to fail to find CurrentNode
I really didn’t find anyone else reporting this issue. I created a custom SiteMapProvider and it magically provided a breadcrumb for me. Sweet! Then I was demo’ing and no breadcrumb…
I discovered that deleting the trailing slash brought the breadcrumb back.
I may have added my SiteMapNode urls incompatibly with the SiteMapProvider expectations. But my urls are perfectly valid and "/my-specialurl" is the same as "/my-special-url/". In my code, I’m stripping trailing slashes before comparison. Shouldn’t the SiteMapProvider do the same? Who knows?
Code change was easy:
(note: I edited this from the original post as I discovered that I overrode the less ideal signiture of this method, this covers both )
public override SiteMapNode FindSiteMapNode(string rawUrl)
{
// base method doesn’t handle trailing slash very well
SiteMapNode match = base.FindSiteMapNode( rawUrl );
// base method worked!
if( match != null ) return match;
// try without trailing slash
if( rawUrl.EndsWith( "/" ) ) match = base.FindSiteMapNode( rawUrl.Substring( 0, rawUrl.Length - 1 ) );
return match;
}
Leave a Reply