-
Notifications
You must be signed in to change notification settings - Fork 1
Defining Sitemap Nodes in XML
The following is a simple sitemap XML file that can be used with the MvcSiteMapProvider:
<?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" changeFrequency="Always" updatePriority="Normal">
<mvcSiteMapNode title="Browse Store" controller="Store" action="Index" />
<mvcSiteMapNode title="Checkout" controller="Checkout" />
</mvcSiteMapNode>
</mvcSiteMap>
Note: There must be exactly 1 root mvcSiteMapNode in the configuration file and the rest of the mvcSiteMapNode elements should be defined below the root node.
The following attributes can be given on an XML node element:
Attribute | Required | Default |
---|---|---|
key | No | (autogenerated) |
The unique identifier for the node. | ||
url | Cond. | (autogenerated based on routes) |
The URL represented by the node. Required if Controller and Action are not provided. | ||
route | No | (empty) |
Can optionally be specified to bind the node URL generation to a specific route. | ||
title | Yes | (empty) |
The title of the node. Localizable. | ||
description | No | (empty) |
Description of the node. Localizable. By default this value will be put into the HTML title attribute of the link. | ||
area | No | (empty) |
The MVC area for the sitemap node. If not specified, it will be inherited from a node higher in the hierarchy. | ||
controller | Yes | (empty) |
The MVC controller for the sitemap node. Case-sensitive! If not specified, it will be inherited from a node higher in the hierarchy. | ||
action | Cond. | (empty) |
The MVC action method for the sitemap node. Required if URL is not specified. | ||
roles | No | (empty) |
Comma-separated list of roles allowed to access the node and its child nodes. | ||
resourceKey | No | (empty) |
Optional implicit resource key for use during localization of the node. | ||
clickable | No | true |
Is the node clickable or just a grouping node? | ||
inheritedRouteParameters | No | (empty) |
Route parameters that should be inherited from the parent sitemap node. | ||
dynamicNodeProvider | No | (empty) |
A class name implementing MvcSiteMapProvider.IDynamicNodeProvider and providing dynamic nodes for the site map. These nodes are cached, not per-request. | ||
urlResolver | No | Sitemap provider's SiteMapNodeUrlResolver instance |
Class that will be used to generate URLs for sitemap nodes. | ||
visibilityProvider | No | (empty); returns true |
Class that will be used to determine visibility for a sitemap node. Default setting can be overridden by the configuration/appSettings value "MvcSiteMapProvider_DefaultSiteMapNodeVisibiltyProvider" in the root web.config file. | ||
visibility | No | (empty) |
Optional extra data that can be passed to a visibility provider to make convention-based visibility. Example from demo: visibility="SiteMapPathHelper,!*" | ||
cacheResolvedUrl | No | true |
Should the resolved URL be cached (true) or resolved on each request (false)? If the preservedRouteParameters attribute is used, this setting will be ignored. | ||
targetFrame | No | (empty) |
Optional target frame for the node link. | ||
imageUrl | No | (empty) |
Optional image to be shown by supported HtmlHelpers. Localizable. | ||
preservedRouteParameters | No | (empty) |
Optional preserved route parameter names (= values that will be used from the current request route). | ||
canonicalUrl | No | (empty) |
Optional. The primary URL for what is completely or mostly duplicated content on the current node. The value may be an absolute URL (in the current site or in an external site), a rooted URL starting with '~/', or a relative URL. Cannot be used in conjunction with canonicalKey. | ||
canonicalKey | No | (empty) |
Optional. The key value for the node that contains the primary copy of the content for the current node, if it is largely similar. Cannot be used in conjunction with canonicalUrl. | ||
metaRobotsValues | No | (empty) |
Optional. A space-delimited list of values to apply to the robots meta tag. These will apply to all robots that crawl the site. Allowed values: index, noindex, follow, nofollow, none, noarchive, nocache, nosnippet, nopreview, noodp, noydir. | ||
lastModifiedDate | No | (empty) |
Last modified date for the node. Will be output to sitemaps XML for search engines. | ||
changeFrequency | No | Undefined |
Change frequency for the node. Will be output to sitemaps XML for search engines. | ||
updatePriority | No | Undefined |
Update priority for the node. Will be output to sitemaps XML for search engines. | ||
httpMethod | No | GET |
The HTTP method that will be used to check node accessibility. This value is used to select correct controller action if a controller has multiple action accepting different HTTP verbs. Set to * or Request to use HTTP method of current request. | ||
order | No | 0 |
The sort order the node will be displayed in the Menu and SiteMap HTML helpers relative to its sibling nodes. | ||
(custom name) | No | (empty) |
Any attributes not defined in this list will automatically be parsed and added to the node.Attributes dictionary. Localizable (string data type only). |
By default, "area" and "controller" (route values only) are automatically inherited from the parent node if they are not explicitly specified. This allows you to use fewer attributes when configuring nodes to make the XML less verbose.
The following two XML declarations will produce exactly the same results, however as you can see the second one requires less markup because it is taking advantage of the default inheritance behavior.
<?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="About" controller="Home" action="About"/>
<mvcSiteMapNode title="Contact" controller="Home" action="Contact"/>
<mvcSiteMapNode title="Products" controller="Products" action="Index">
<mvcSiteMapNode title="Flashlight" controller="Products" action="Details" id="1"/>
<mvcSiteMapNode title="AA Battery" controller="Products" action="Details" id="2"/>
</mvcSiteMapNode>
<mvcSiteMapNode title="Administration" area="Admin" controller="Home" action="Index">
<mvcSiteMapNode title="Manage Products" area="Admin" controller="Products" action="Manage"/>
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
<?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="About" action="About"/>
<mvcSiteMapNode title="Contact" action="Contact"/>
<mvcSiteMapNode title="Products" controller="Products" action="Index">
<mvcSiteMapNode title="Flashlight" action="Details" id="1"/>
<mvcSiteMapNode title="AA Battery" action="Details" id="2"/>
</mvcSiteMapNode>
<mvcSiteMapNode title="Administration" area="Admin" controller="Home" action="Index">
<mvcSiteMapNode title="Manage Products" controller="Products" action="Manage"/>
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
You can also specify additional route values to inherit, including custom attributes, by adding the name of the value to the inheritedRouteParameters. Multiple values should be separated by a comma.
The following 2 XML declarations will have exactly the same result.
<?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="Products" controller="Products" action="Index">
<mvcSiteMapNode title="Flashlight" action="Details" id="1" type="product"/>
<mvcSiteMapNode title="AA Battery" action="Details" id="2" type="accessory"/>
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
<?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="Products" controller="Products" action="Index" type="accessory">
<mvcSiteMapNode title="Flashlight" action="Details" id="1" type="product"/>
<mvcSiteMapNode title="AA Battery" action="Details" id="2" inheritedRouteParameters="type"/>
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMap>
- [Wiki Home] (.)
- [Release Notes] (https://github.com/maartenba/MvcSiteMapProvider/releases)
Want to contribute? See our [Contributing to MvcSiteMapProvider] (https://github.com/maartenba/MvcSiteMapProvider/blob/master/CONTRIBUTING.md) guide.
- [Upgrading from v3 to v4] (Upgrading-from-v3-to-v4)
- [Routing Basics] (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] (Multiple-Sitemaps-in-One-Application)
- [Security Trimming] (Security-Trimming)
[Version 3.x Documentation] (Version-3.x-Documentation)
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] (http://www.shiningtreasures.com/post/2013/08/07/MvcSiteMapProvider-40-a-test-drive)
- [MvcSiteMapProvider 4.0 - SEO Features Tutorial] (http://www.shiningtreasures.com/post/2013/08/10/mvcsitemapprovider-4-seo-features)
- [How to Make MvcSiteMapProvider Remember a User’s Position] (http://www.shiningtreasures.com/post/2013/09/02/how-to-make-mvcsitemapprovider-remember-a-user-position)
- [MvcSiteMapProvider 4.0 - Cache Configuration] (http://www.shiningtreasures.com/post/2013/08/11/mvcsitemapprovider-4-cache-configuration)
- [MvcSiteMapProvider 4.0 - Extending the Cache] (http://www.shiningtreasures.com/post/2013/08/13/mvcsitemapprovider-4-extending-the-cache)
- [MvcSiteMapProvider 4.0 - Unit Testing with the SiteMaps Static Methods] (http://www.shiningtreasures.com/post/2013/08/14/mvcsitemapprovider-4-unit-testing-with-the-sitemaps-static-methods)
- [Debugging an MvcSiteMapProvider Configuration] (http://www.shiningtreasures.com/post/2013/08/21/debugging-an-mvcsitemapprovider-configuration)
- [Converting from C# to Vb MvcSiteMapProvider] (http://www.developerfusion.com/thread/112710/converting-from-c-to-vb-mvcsitemapprovider/)
- [NightOwl888's MvcSiteMapProvider Demos] (https://github.com/NightOwl888?tab=repositories) - Filter for "MvcSiteMapProvider" to see the most relevant.
- [MvcSiteMapProvider Tutorial and Examples] (http://edspencer.me.uk/2011/02/10/mvc-sitemap-provider-tutorial/)
- [MvcSiteMapProvider Tutorial 2 - Breadcrumbs] (http://edspencer.me.uk/2011/09/20/mvc-sitemap-provider-tutorial-2-breadcrumbs/)
- [Getting Started with MvcSiteMapProvider] (http://blog.danstuken.com/2011/04/29/getting-started-with-mvcsitemapprovider/)
- [Inside the MvcSiteMapProvider - Part 1] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-1.html)
- [Inside the MvcSiteMapProvider - Part 2: Dynamic node providers] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-2.html)
- [Inside the MvcSiteMapProvider - Part 3: The ISiteMapVisibilityProvider] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-3.html)
- [Inside the MvcSiteMapProvider - Part 4: The IAclModule] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-4.html)
- [Inside the MvcSiteMapProvider - Part 5: The ISiteMapNodeUrlResolver] (http://xharze.blogspot.com/2012/04/inside-mvcsitemapprovider-part-5.html)
- [Styling MvcSiteMapProvider with CSS] (http://tutsblog.net/styling-mvc-sitemap-provider-with-css/)
- [Using MvcSiteMapProvider with Twitter Bootstrap] (http://codingit.wordpress.com/2013/05/03/using-mvcsitemapprovider-with-twitter-bootstrap/)
- [ASP.NET MVC Menu using Site Map Provider & Bootstrap Navbar] (http://joeylicc.wordpress.com/2013/06/04/asp-net-mvc-menu-using-site-map-provider-bootstrap-navbar/)
- [StackOverflow MvcSiteMapProvider] (http://stackoverflow.com/questions/tagged/mvcsitemapprovider)
- [StackOverflow MvcSiteMap] (http://stackoverflow.com/questions/tagged/mvcsitemap)
- [StackOverflow ASP.NET MVC SiteMap] (http://stackoverflow.com/questions/tagged/asp.net-mvc-sitemap)
- [CodePlex Discussion Forum (no longer maintained)] (http://mvcsitemap.codeplex.com/discussions/topics/general?size=2147483647)
- [Telerik Forum] (http://www.telerik.com/search.aspx?insection=False&start=0&client=telerik_developer_tools&q=MvcSiteMapProvider&sid=1)
- [maartenba's blog] (http://blog.maartenballiauw.be/search.aspx?q=mvcsitemapprovider)
- [NightOwl888's blog] (http://www.shiningtreasures.com/category/MvcSiteMapProvider)