The simplest way to create a site map is to create an XML file named Web.sitemap that organizes the pages in the site hierarchically. This site map is automatically picked up by the default site-map provider for ASP.NET.
The Web.sitemap file must be located in the application root directory, though it can reference other site-map providers, or other site-map files in other directories as long as those files are in the same application. For more information, see How to: Configure Multiple Site Maps and Site-Map Providers.
Security Note: |
|---|
Implementing a custom site-map provider that stores site-map data in a file with a file name extension other than .sitemap is a potential security risk. By default, ASP.NET is configured to protect files with known file name extensions — such as .sitemap — from being downloaded by a client. To help protect your data, place any custom site-map data files that have a file name extension other than .sitemap in the App_Data folder. For more information, see
Securing ASP.NET Site Navigation.
|
The following code example shows how the site map might look for a simple site that goes three levels deep. The url attribute can start with the "~/" shortcut which indicates the application root. For more information, see ASP.NET Web Site Paths.
|
<siteMap>
<siteMapNode title="Home" description="Home" url="~/default.aspx">
<siteMapNode title="Products" description="Our products"
url="~/Products.aspx">
<siteMapNode title="Hardware" description="Hardware choices"
url="~/Hardware.aspx" />
<siteMapNode title="Software" description="Software choices"
url="~/Software.aspx" />
</siteMapNode>
<siteMapNode title="Services" description="Services we offer"
url="~/Services.aspx">
<siteMapNode title="Training" description="Training classes"
url="~/Training.aspx" />
<siteMapNode title="Consulting" description="Consulting services"
url="~/Consulting.aspx" />
<siteMapNode title="Support" description="Supports plans"
url="~/Support.aspx" />
</siteMapNode>
</siteMapNode>
</siteMap>
|
In the Web.sitemap file, add a siteMapNode element for each page in your Web site. Then you can create the hierarchy by nesting siteMapNode elements. In the preceding example, the pages for Hardware and Software are child elements of the Products siteMapNode element. The title attribute defines the text that is usually used as link text, and the description attribute acts both as documentation and as a tool tip in the SiteMapPath control.
Note: |
|---|
In a site map, you can reference URLs that are outside of your Web application. Access to a URL outside of the application cannot be tested by ASP.NET. Therefore if you enable security trimming, the site-map node will not be visible unless you set the roles attribute to "*", which enables all clients to view the site-map node without first testing access to the URL. For more information, see
ASP.NET Site-Map Security Trimming.
|