-
Notifications
You must be signed in to change notification settings - Fork 218
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 |
---|---|---|
Yes | (empty) | |
The title of the node. Localizable. | ||
No | (value of title attribute) | |
Description of the node. Localizable. This value will be put into the HTML title attribute of the link. Default can be changed to empty string by setting the configuration/appSettings value "MvcSiteMapProvider_UseTitleIfDescriptionNotProvided" in the root web.config file to "false". | ||
No | true | |
Is the node clickable or just a grouping node? | ||
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. | ||
No | (empty) | |
Optional extra data that can be passed to a visibility provider to make convention-based visibility. Example from demo: visibility="SiteMapPathHelper,!*" | ||
No | 0 | |
The sort order the node will be displayed in the Menu and SiteMap HTML helpers relative to its sibling nodes. | ||
No | (empty) | |
Optional image to be shown by supported HtmlHelpers. Localizable. The value may be an absolute URL (to the current site or to an external site), root relative URL (starting with '/' ), or virtual application relative URL (starting with '~/' ). | ||
Cond. | (empty); protocol of current request if imageUrlHostName attribute supplied | |
The protocol that will be used to generate the imageUrl, such as http, https, or ftp. Defaults to the protocol of the current request if imageUrlHostName attribute is supplied. | ||
Cond. | (empty); current request host name if imageUrlProtocol attribute supplied | |
The host name that will be used to generate the imageUrl, such as www.somewhere.com. Defaults to the host name of the current request if imageUrlProtocol attribute is supplied. | ||
No | (empty) | |
Optional target frame for the node link. | ||
Attribute | Required? | Default |
No | (empty) | |
The MVC area for the sitemap node. If not specified, it will be inherited from a node higher in the hierarchy. | ||
Yes | (empty) | |
The MVC controller for the sitemap node. Case-sensitive! Must not end in the suffix "Controller". If not specified, it will be inherited from a node higher in the hierarchy. | ||
Cond. | (empty) | |
The MVC action method for the sitemap node. Required if URL is not specified. | ||
No | (empty) | |
Can be specified to bind the node URL generation to a specific route. | ||
No | (empty) | |
Route parameters that should be inherited from the parent sitemap node in the XML hierarchy. | ||
No | (empty) | |
Preserved route parameter names (= values that will be used from the current request route). | ||
No | Sitemap provider's SiteMapNodeUrlResolver instance | |
Class that will be used to generate URLs for sitemap nodes. | ||
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. | ||
Cond. | (autogenerated based on routes) | |
The URL represented by the node. Required if Controller and Action are not provided. The value may be an absolute URL (to the current site or to an external site), root relative URL (starting with '/' ), or virtual application relative URL (starting with '~/' ). | ||
Cond. | (empty); http if hostName attribute supplied | |
The protocol that will be used to generate the URL, such as http, https, or ftp. Defaults to "http" if hostName attribute is supplied. Set to "*" to use the protocol of the current request. | ||
Cond. | (empty); current request host name if protocol attribute supplied | |
The host name that will be used to generate the URL, such as www.somewhere.com. Defaults to the host name of the current request if protocol attribute is supplied. | ||
Cond. | false | |
Whether or not to include non-configured route values and/or query string values from the current user's request when resolving the URL. This setting affects route/action URLs only, if you set the url attribute explicitly, this setting has no effect. | ||
Attribute | Required? | Default |
No | (empty) | |
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. | ||
No | (empty) | |
The primary URL for what is completely or mostly duplicated content on the current node. The value may be an absolute URL (to the current site or to an external site), root relative URL (starting with '/' ), or virtual application relative URL (starting with '~/' ). Cannot be used in conjunction with canonicalKey. | ||
Cond. | (empty); http if canonicalUrlHostName attribute supplied | |
The protocol that will be used to generate the URL, such as http, https, or ftp. Defaults to "http" if canonicalUrlHostName attribute is supplied. Set to "*" to use the protocol of the current request. | ||
Cond. | (empty); current request host name if canonicalUrlProtocol attribute supplied | |
The host name that will be used to generate the URL, such as www.somewhere.com. Defaults to the host name of the current request if canonicalUrlProtocol attribute is supplied. | ||
No | (empty) | |
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. | ||
No | (empty) | |
Last modified date for the node. Will be output to sitemaps XML for search engines. | ||
No | Undefined | |
Change frequency for the node. Will be output to sitemaps XML for search engines. | ||
No | Undefined | |
Update priority for the node. Will be output to sitemaps XML for search engines. | ||
Attribute | Required? | Default |
No | (autogenerated) | |
The unique identifier for the node. | ||
No | (empty) | |
A class name implementing MvcSiteMapProvider.IDynamicNodeProvider and providing dynamic nodes for the site map. These nodes are cached, not per-request. | ||
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. | ||
No | (empty) | |
Comma-separated list of roles allowed to access the node and its child nodes. This attribute is for interoperability with non-MVC pages that are secured using ASP.NET forms authentication. For MVC, use the AuthorizeAttribute to provide security. | ||
No | (empty) | |
Implicit resource key for use during localization of the node. | ||
No | (empty) | |
Any attributes not defined in this list will automatically be parsed and added to the ISiteMapNode.Attributes dictionary and ISiteMapNode.RouteValues dictionary. To exclude the attribute from being added to the RouteValues dictionary (and thus the URL), add the attribute name to the configuration/appSettings value "MvcSiteMapProvider_AttributesToIgnore" in the root web.config file as a comma delimited list. Localizable (if string data type). |
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" type="accessory">
<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>
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