SiteMap Controls: How to add a duplicate link in the web.sitemap

来源:互联网 发布:ssr客户端 for mac 编辑:程序博客网 时间:2024/05/17 04:28

 

One of the requirements for the sitemap provider is that you cannot have duplicate url attribute values in the web.sitemap. While this is understandable, it can be problematic but easily overcome.

Lets say you have a hierarchy like

<siteMap>
<siteMapNode url="" title="categorylvl1" >
<siteMapNode url="" title="categorylvl1a" >
<siteMapNode url="/path.aspx" title="categorylvl1b" />
<siteMapNode>
<siteMapNode>
<siteMapNode url="" title="categorylvl2" >
<siteMapNode url="/otherpath.aspx" title="categorylvl2a" />
<siteMapNode/>
</siteMap>

right? so you have one Category (lvl1) that has a depth of 3, andy you have antoher that has a depth of 2. Now you only want to show 2 levels deep because you've designed your menu treeview such that the nodes are stacked up on eachother instead of arranged like a tree which really only provides enough for a 2 level display:

Category (no url attribute assigned)
Link
Category
Link

etc etc...but your display actually turns out to be something like

Category (no url attribute assigned)
SubCategory (no url attribute assigned)
(3rd level node is not shown)
Category
Link

And now you say to yourself, how in the hell do I put a duplicate path in the web.sitemap so I can have SubCategories go to the first (3rd level) link for that category? Well, the first thing that comes to mind is:
1. You should have a page for ALL categories regardless of if there is no official "content" for those categories. At the very least you should have some page with SOMETHING on it as (in my opinion) this breaks a fundamental rule of navigation and user expectation. That rule is, " if it's in the menu, they'll want to click on it".

2. If you find yourself in a tight spot like I did today with the same situation and of course the category levels were empty and I was stacking my hierarchy only 2 nodes deep which left me with non-clickable categories; the answer to is to put a querystring in the url for the "duplicate" url attribute.


<siteMap>
<siteMapNode url="" title="categorylvl1" >
<siteMapNode url="/path.aspx?" title="categorylvl1a" >
<siteMapNode url="/path.aspx" title="categorylvl1b" />
<siteMapNode>
<siteMapNode>
<siteMapNode url="" title="categorylvl2" >
<siteMapNode url="/otherpath.aspx" title="categorylvl2a" />
<siteMapNode/>
</siteMap>

You should be able to just add random characters at the end as they will most likely be ignored should you need to do this more than once for the same path. Even better would be to convince your client or boss that Rule #1 should be followed :)
原创粉丝点击