There are 2 ways to use an "id" or any other route value with MvcSiteMapProvider.
1. Create a node for each "id" (usually this is done with a DynamicNodeProviderBase implementation). This gives you a 1-to-1 relationship between the "id" value and the node. Use this method if you have < 10,000 nodes and you want them all indexed by search engines.
<mvcSiteMapNode title="Product 1" controller="Product" action="Details" id="1"/>
<mvcSiteMapNode title="Product 2" controller="Product" action="Details" id="2"/>
<mvcSiteMapNode title="Product 3" controller="Product" action="Details" id="3"/>
2. Create a single node to match all "id" values by setting preservedRouteParameters="id" on the node. This will give you a 1-to-1 relastionship between the route parameter name "id" (the value doesn't matter) and the node. This only works for the breadcrumb trail; for the Menu, SiteMap, and /sitemap.xml endpoints, you will need to use a visibility provider as well as a SiteMapTitle attribute to fix the display of the UI. Use this method for administration pages that edit data and will never be seen by search engines.
<mvcSiteMapNode title="Product 1" controller="Product" action="Details" preservedRouteParameters="id"/>
Note that you can also combine both techniques on the same node if you have multiple parameters. If, for example you have a user specific "userId" parameter that search engines will never need to know about, you can reduce the number of nodes (normally you would need to provide a node for [all "id" values] X [all "userId" values] - that is, the total node count would equal the product of all of the potential value combinations) in the SiteMap by always matching the "userId", but still index all of the products.
<mvcSiteMapNode title="Product 1" controller="Product" action="Details" id="1" preservedRouteParameters="userId"/>
<mvcSiteMapNode title="Product 2" controller="Product" action="Details" id="2" preservedRouteParameters="userId"/>
<mvcSiteMapNode title="Product 3" controller="Product" action="Details" id="3" preservedRouteParameters="userId"/>
Note also that you don't have to use XML to use these techniques - they also work when declaring nodes in other ways.
There is a complete article that describes each of these techniques with downloadable working samples on my blog: How to Make MvcSiteMapProvider Remember a User's Position.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…