Export (0) Print
Expand All

How to: Programmatically Enumerate Site-Map Nodes 

You can use navigation controls to add site navigation to your Web pages with little or no code, but you can also work with site navigation programmatically. When your Web application runs, ASP.NET creates a SiteMap object that reflects the structure of the site map. The SiteMap object, in turn, exposes a collection of SiteMapNode objects that contain properties for each node in the site map.

Navigation controls such as the SiteMapPath control work with the SiteMap and SiteMapNode objects to render the appropriate links automatically.

You can use the SiteMap and SiteMapNode objects in your own code to create custom navigation.

Example

The following code example shows how to display the titles of all of the child nodes for the current page, as long as the current page is listed in the site-map file. If the current page is not listed in the site-map file, the first line of code that uses the SiteMap object will cause a NullReferenceException exception.

No code example is currently available or this language may not be supported.

Security

You can hide the links in your navigation structure from users in specified security roles. For more information, see ASP.NET Site-Map Security Trimming.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft