-
Notifications
You must be signed in to change notification settings - Fork 218
Multiple Navigation Paths to a Single Page
A common requirement is when a particular product or article fits into multiple categories, you want to be able to navigate to that page using multiple paths. For example:
Home > Red Things > Red Beans
Home > Beans > Red Beans
But how can you do this if a site map node must be unique? The answer is to use 2 site map nodes to point to a single resource. This can be done by either adding query string information to the end of the URL, or by using a different URL path entirely for the alternate navigation. However it is done, the URLs in each case must be unique. Here are some examples:
Differentiating by query string
http://mysite.com/products/index/red-beans?category=red-things
http://mysite.com/products/index/red-beans?category=beans
Differentiating by path
http://mysite.com/red-things/red-beans
http://mysite.com/beans/red-beans
http://mysite.com/on-sale/red-beans
If you are familiar with routing in .NET, you probably already have an idea how to set up your URLs using a method similar to this. The first method is the simplest - add an extra category parameter to the route and it will automatically be generated that way. The only requirement is that you set up each node on a different physical URL.
Yes and no. It is bad if you only put the content on different URLs and do nothing else. However, we have provided the framework to easily take advantage of the canonical tag, which is how you can tell search engines you meant to put the same content on multiple URLs. Here is what the XML configuration would look like for the first example above, but keep in mind that you can also set these settings from any of the other methods of building site map nodes.
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="Red Things" controller="categories" action="Index" id="red-things">
<mvcSiteMapNode title="Red Beans" controller="products" action="Index" id="red-beans-67" category="red-things" key="red-beans" />
</mvcSiteMapNode>
<mvcSiteMapNode title="Beans" controller="categories" action="Index" id="beans">
<mvcSiteMapNode title="Red Beans" controller="products" action="Index" id="red-beans-67" category="beans" canonicalKey="red-beans" />
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
In short, the key property of the "main" node must be specified as a canonicalKey in all of the alternate nodes that reach the same resource. Alternatively, you can specify the relationship using canonicalUrl, which is useful if the original page is not on the current web site or you are using a scheme with URLs instead of routes. canonicalKey and canonicalUrl may not be used simultaneously on the same node.
Then you just need to add the canonical helper to your layout page between the <head>
tags using the following syntax:
<head>
@Html.MvcSiteMap().CanonicalTag()
</head>
The correct canonical tag will then be generated automatically. In addition, the `XmlSiteMapController` (`sitemap.xml` page) will automatically exclude the "extra" URLs so the information that the search engines receive is consistently recommending the canonical (authoritive) URL for the index.
Want to contribute? See our Contributing to MvcSiteMapProvider guide.
- Upgrading from v3 to v4
- Routing Basics
- Configuring MvcSiteMapProvider
- Defining Sitemap Nodes in XML
- Defining Sitemap Nodes using .NET Attributes
- Defining Sitemap Nodes using IDynamicNodeProvider
- HtmlHelper Extensions
- Controlling URL Behavior
- Using Action Filter Attributes
- Sitemaps XML Protocol Endpoint for Search Engines
- Using Custom Attributes on a Node
- Specifying Node Order
- Advanced Node Visibility
- Multiple Navigation Paths to a Single Page
- Multiple Sitemaps in One Application
- Security Trimming
Other places around the web have some documentation that is helpful for getting started and finding answers that are not found here.
- MvcSiteMapProvider 4.0 - A Test Drive
- MvcSiteMapProvider 4.0 - SEO Features Tutorial
- How to Make MvcSiteMapProvider Remember a User’s Position
- MvcSiteMapProvider 4.0 - Cache Configuration
- MvcSiteMapProvider 4.0 - Extending the Cache
- MvcSiteMapProvider 4.0 - Unit Testing with the SiteMaps Static Methods
- Debugging an MvcSiteMapProvider Configuration
- Converting from C# to Vb MvcSiteMapProvider
- ASP.NET MVC Menu using Site Map Provider & Bootstrap 3 Navbar
- ASP.NET MVC SiteMapPath using Site Map Provider & Bootstrap Breadcrumbs
- NightOwl888's MvcSiteMapProvider Demos - Filter for "MvcSiteMapProvider" to see the most relevant.
- MvcSiteMapProvider Tutorial and Examples
- MvcSiteMapProvider Tutorial 2 - Breadcrumbs
- Getting Started with MvcSiteMapProvider
- Inside the MvcSiteMapProvider - Part 1
- Inside the MvcSiteMapProvider - Part 2: Dynamic node providers
- Inside the MvcSiteMapProvider - Part 3: The ISiteMapVisibilityProvider
- Inside the MvcSiteMapProvider - Part 4: The IAclModule
- Inside the MvcSiteMapProvider - Part 5: The ISiteMapNodeUrlResolver
- Styling MvcSiteMapProvider with CSS
- Using MvcSiteMapProvider with Twitter Bootstrap
- ASP.NET MVC Menu using Site Map Provider & Bootstrap Navbar