maartenba / MvcSiteMapProvider

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

Support for hash fragment (named Ancors) nodes #457

Closed joaocarlosleme closed 7 years ago

joaocarlosleme commented 7 years ago

Getting the error

Multiple nodes with the same URL 'example.org/contact/#location' were found. SiteMap requires that sitemap nodes have unique URLs

on sitemap with URLs differentiated by fragments.

Before on v3 had no problem, even though MvcSiteMapProvider would not pickup the fragment for the current node.

Unless there is already a solution for this (?) I would recommend removing the error and solving the current node issue passing the fragment through a cookie (add a javascript file to save/delete the cookie/var).

Either way, its better to have the main page as current node (match to url node without the fragment) than not allowing nodes differentiated by fragments (better on v3 than v4).

NightOwl888 commented 7 years ago

There is no possible way for the SiteMap to support fragments, since browsers do not reliably send them back to the server where they can be processed. You are welcome to complain to the browser manufacturers if you wish, but there is nothing we can do from this end.

The SiteMap is a model that represents unique navigation points on the server-side within the MVC application. If you need to change the client-side, then you should change the views in /Views/Shared/DisplayTemplates. You can use custom attributes to provide data to your view logic, as needed.

If you need more control than that, you can make your own HTML helper with custom view models. See this comment for an example.

Also, removing the error is a step backwards - we actually could use more validation to ensure the SiteMap is not abused. In v3, it seemed there were as many different unofficial ways to configure it as there were developers configuring it. In Microsoft's original design, there is validation to ensure no duplicate URLs can be entered. Since the design depends heavily on the uniqueness of the nodes, this completely makes sense. So, we followed suit. It works for anyone who uses it correctly, and doesn't work anymore for those who found some unsupported way to hack it together.

I am closing this issue as a won't fix (actually can't fix) because there is literally no way to accomplish what you are suggesting. If there were a possible way to support fragments, you can bet we would have done it. You just need to respect the MVC pattern and don't try to put view logic into the model - use the upper layers to handle presentation logic where it belongs.

joaocarlosleme commented 7 years ago

I guess I will have to fork and start my own branch