To implement a site-map provider, create a class that inherits the SiteMapProvider abstract class from the System.Web namespace, and then implement the abstract members that are exposed by the SiteMapProvider class. This topic describes the required properties and methods that you must implement from the SiteMapProvider abstract classes. To review an implementation of each member, see the example code supplied for the Microsoft Access- and text-based site-map providers in How to: Implement ASP.NET Site-Map Providers.
Note: |
|---|
The
SiteMapProvider class imposes one constraint on the structure of the site-map data: only one root node can exist. The implementation of the default ASP.NET site-map provider also specifies that URLs must be unique within the scope of the provider, but custom site-map providers do not have this limitation.
|
Required SiteMapProvider Members
The following table lists the only methods that are required to implement a custom site-map provider. The SiteMapProvider base class provides a minimal implementation.
Method
|
Description
|
|---|
FindSiteMapNode
|
Retrieves an instance of the SiteMapNode class, which represents a page. This method is overloaded.
|
GetChildNodes
|
Retrieves the child nodes of a specific instance of the SiteMapNode class.
|
GetParentNode
|
Retrieves the parent node of a specific instance of the SiteMapNode class.
|
GetRootNodeCore
|
Retrieves the root node of all the nodes that are managed by the current provider. This method is called internally by various site navigation classes to ensure that the navigation data has been loaded by the provider. This method must not return a null node.
|
If you are satisfied with the semantics of the XmlSiteMapProvider class but want to use a different data store than the Web.sitemap file, then you should derive from the StaticSiteMapProvider class instead of the SiteMapProvider class. Otherwise, some methods, such as the AddNode and RemoveNode methods, will throw a NotImplementedException unless they are implemented. The StaticSiteMapProvider class provides all of the internal logic for storing and searching nodes; you only need to implement the GetRootNodeCore method and the abstract BuildSiteMap method. The GetRootNodeCore method can simply call the BuildSiteMap method.