Export (0) Print
Expand All

SiteMapProvider Class

Provides a common base class for all site map data providers, and a way for developers to implement custom site map data providers that can be used with the ASP.NET site map infrastructure as persistent stores for SiteMap objects.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)

[<AbstractClass>]
type SiteMapProvider =  
    class
        inherit ProviderBase
    end

The SiteMapProvider type exposes the following members.

  NameDescription
Protected methodSiteMapProviderInitializes a new instance of the SiteMapProvider class.
Top

  NameDescription
Public propertyCurrentNodeGets the SiteMapNode object that represents the currently requested page.
Public propertyDescriptionGets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs). (Inherited from ProviderBase.)
Public propertyEnableLocalizationGets or sets a Boolean value indicating whether localized values of SiteMapNode attributes are returned.
Public propertyNameGets the friendly name used to refer to the provider during configuration. (Inherited from ProviderBase.)
Public propertyParentProviderGets or sets the parent SiteMapProvider object of the current provider.
Public propertyResourceKeyGet or sets the resource key that is used for localizing SiteMapNode attributes.
Public propertyRootNodeGets the root SiteMapNode object of the site map data that the current provider represents.
Public propertyRootProviderGets the root SiteMapProvider object in the current provider hierarchy.
Public propertySecurityTrimmingEnabledGets a Boolean value indicating whether a site map provider filters site map nodes based on a user's role.
Top

  NameDescription
Protected methodAddNode(SiteMapNode)Adds a SiteMapNode object to the node collection that is maintained by the site map provider.
Protected methodAddNode(SiteMapNode, SiteMapNode)Adds a SiteMapNode object to the node collection that is maintained by the site map provider and specifies the parent SiteMapNode object.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFindSiteMapNode(HttpContext)Retrieves a SiteMapNode object that represents the currently requested page using the specified HttpContext object.
Public methodFindSiteMapNode(String)When overridden in a derived class, retrieves a SiteMapNode object that represents the page at the specified URL.
Public methodFindSiteMapNodeFromKeyRetrieves a SiteMapNode object based on a specified key.
Public methodGetChildNodesWhen overridden in a derived class, retrieves the child nodes of a specific SiteMapNode.
Public methodGetCurrentNodeAndHintAncestorNodesProvides an optimized lookup method for site map providers when retrieving the node for the currently requested page and fetching the parent and ancestor site map nodes for the current page.
Public methodGetCurrentNodeAndHintNeighborhoodNodesProvides an optimized lookup method for site map providers when retrieving the node for the currently requested page and fetching the site map nodes in the proximity of the current node.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetParentNodeWhen overridden in a derived class, retrieves the parent node of a specific SiteMapNode object.
Public methodGetParentNodeRelativeToCurrentNodeAndHintDownFromParentProvides an optimized lookup method for site map providers when retrieving an ancestor node for the currently requested page and fetching the descendant nodes for the ancestor.
Public methodGetParentNodeRelativeToNodeAndHintDownFromParentProvides an optimized lookup method for site map providers when retrieving an ancestor node for the specified SiteMapNode object and fetching its child nodes.
Protected methodGetRootNodeCoreWhen overridden in a derived class, retrieves the root node of all the nodes that are currently managed by the current provider.
Protected methodStatic memberGetRootNodeCoreFromProviderRetrieves the root node of all the nodes that are currently managed by the specified site map provider.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodHintAncestorNodesProvides a method that site map providers can override to perform an optimized retrieval of one or more levels of parent and ancestor nodes, relative to the specified SiteMapNode object.
Public methodHintNeighborhoodNodesProvides a method that site map providers can override to perform an optimized retrieval of nodes found in the proximity of the specified node.
Public methodInitializeInitializes the SiteMapProvider implementation, including any resources that are needed to load site map data from persistent storage. (Overrides ProviderBase.Initialize(String, NameValueCollection).)
Public methodIsAccessibleToUserRetrieves a Boolean value indicating whether the specified SiteMapNode object can be viewed by the user in the specified context.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodRemoveNodeRemoves the specified SiteMapNode object from the node collection that is maintained by the site map provider.
Protected methodResolveSiteMapNodeRaises the SiteMapResolve event.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventSiteMapResolveOccurs when the CurrentNode property is called.
Top

The StaticSiteMapProvider and XmlSiteMapProvider classes represent the default implementations of the abstract SiteMapProvider class. The XmlSiteMapProvider uses an XML file named Web.sitemap to store site map data. For more information on about the Web.sitemap file, see ASP.NET Site Maps.

The SiteMapProvider class supports the concept of a site map provider hierarchy, by declaring the RootProvider and ParentProvider properties. A SiteMapProvider can be a child or parent of another provider. This enables scenarios where different content areas of a site are owned or implemented by different development groups that maintain their own site maps and site map providers.

All SiteMapProvider objects are configured in the Web.config files. Any site map providers that are declared in these configuration files are loaded at run time and are used to load and process site navigation data. The SiteMap object, which keeps track of all the providers that are available to it through its Providers property collection, provides programmatic access to the navigation data that is managed by the providers. The following code example demonstrates the format that is used to declare a site map provider in a Web.config file.

<siteMap defaultProvider="<name>">
  <providers>
    <add
      name="<friendly name>"
      type="<fully qualified class name>, <assembly name (optional)>" 
      siteMapFile = "<file name>" />
  </providers>
</siteMap>

The site navigation data that is loaded by these providers is used by other components of the site map infrastructure, such as the SiteMapPath and TreeView controls, to display site map information for users.

If you implement your own site map provider, you can place the source file in the App_Code directory of your ASP.NET application, and then the assembly will be compiled automatically. You can also place your own site map provider in the Global Assembly Cache (GAC), and provide a fully-qualified reference to it in the Web.config file. For more information on compiler services, see Working with Assemblies and the Global Assembly Cache.

Notes to Inheritors

When you inherit from the SiteMapProvider class, you must override the following members: GetRootNodeCore, FindSiteMapNode, GetChildNodes, and GetParentNode.

The following code example demonstrates how to write a class that implements the abstract SiteMapProvider class. This example includes only a sample SiteMapProvider and a sample text file that works with it. To run the example you also need an entry in the Web.config file and an .aspx page. You can find these in the documentation for the SiteMapDataSource.SiteMapProvider property.

The example uses a comma-delimited file that follows an expected structure to load sitemap information. The first line of the file represents the root node of the sitemap, and subsequent lines are subnodes. Each subnode identifies its parent node by URL. An example of a file that meets these criteria is shown below.

default.aspx,Home,MyCompany Home Page,
sale.aspx,Now On Sale,Check Out These Great Deals!,default.aspx
catalog.aspx,Online Catalog,Browse Our Many Great Items!,default.aspx

The SimpleTextSiteMapProvider provides example implementations of all the SiteMapProvider properties and methods.

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft