maartenba / MvcSiteMapProvider

An ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework.
Microsoft Public License
537 stars 220 forks source link

Possible issue when building Dynamic Node sitemap that contains some URLs that point to External sites #456

Open MelissaSnell opened 7 years ago

MelissaSnell commented 7 years ago

Hi there.

I just wanted to ask if anyone has reported any issues when generating a Dynamic site map, when some of the Dynamic nodes have a URL that points to an external web site?

My site map is generated from a database managed by a CMS and it has been working well. I already had two nodes where the url property was set to an external site (starting with either https:// or http://) without issues. However when I added a third node I was receiving the message that the sitemap contained more than one node with {new-external-url}. This third node had the same "parent" as one of the other nodes that pointed to an external URL.

I've tried adding another external link to another parent and I get the same error. So it seems that I can't add more than one Dynamic node with a url that points to an external link for the same top-level parent.

The error was: Multiple nodes with the same URL '{external-domain}' were found. SiteMap requires that sitemap nodes have unique URLs.

I am using runtime version v4.0.30319 and am using a .net 4.5 MVC4 application.

I've checked the database (only one occurrence) and I've watched the code generate the sitemap node-by-node, and the url in question only appears once. So I am at a loss to understand why.

Has anyone reported this and if you have time any tips you might have relating to working out which node/s might be causing the issue would be gratefully received. Many thanks in advance

NightOwl888 commented 7 years ago

First of all, let's be clear on one thing - there is no such thing as a "dynamic site map". There are "dynamic node providers", which are for adding nodes to the static sitemap from a dynamic data source. The name "dynamic node provider" was an unfortunate design choice that was before my time on this project.

That said, there might be something else going on here. This might occur if you have tried to set the cache timeout to 0. Could you put together a small demo project that shows the broken behavior? Either zip it and post it where it can be downloaded or put it on GitHub.

MelissaSnell commented 7 years ago

Hi there. Many thanks for your reply, and for all your work on this codebase.

Sorry about the term "Dynamic Site Map" - I take your point that it is not technically correct but it's a habit I've formed when referring to it in discussions with the end-users, who's eyes would glaze over if I started referring to dynamic node providers!

I am caching the sitemap for 5 minutes.

I found a work around by using the Attributes of the DynamicNode for "AlternativeUrl", which is where I store the external absolute URL, and then I created a modified Display template for the SiteMapNodes for the Menu that uses the AlternativeURL attribute value (if found). This seems to work well as a solution.

I will try to put together a demo project to see if I can duplicate the problem. If I can I will post it here, but that might not be for a few weeks.

Many thanks once again.