Export (0) Print
Expand All

XmlSiteMapProvider Class

The XmlSiteMapProvider class is derived from the SiteMapProvider class and is the default site map provider for ASP.NET. The XmlSiteMapProvider class generates site map trees from XML files with the file name extension .sitemap.

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

public ref class XmlSiteMapProvider : public StaticSiteMapProvider, 
	IDisposable

The XmlSiteMapProvider type exposes the following members.

  NameDescription
Public methodXmlSiteMapProviderCreates a new, unnamed, instance of the XmlSiteMapProvider class.
Top

  NameDescription
Public propertyCurrentNodeGets the SiteMapNode object that represents the currently requested page. (Overrides SiteMapProvider::CurrentNode.)
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. (Inherited from SiteMapProvider.)
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. (Inherited from SiteMapProvider.)
Public propertyResourceKeyGet or sets the resource key that is used for localizing SiteMapNode attributes. (Inherited from SiteMapProvider.)
Public propertyRootNodeGets the root node of the site map. (Overrides SiteMapProvider::RootNode.)
Public propertyRootProviderGets the root SiteMapProvider object in the current provider hierarchy. (Inherited from SiteMapProvider.)
Public propertySecurityTrimmingEnabledGets a Boolean value indicating whether a site map provider filters site map nodes based on a user's role. (Inherited from SiteMapProvider.)
Top

  NameDescription
Protected methodAddNode(SiteMapNode)Adds a SiteMapNode object to the node collection that is maintained by the site map provider. (Inherited from SiteMapProvider.)
Protected methodAddNode(SiteMapNode, SiteMapNode)Adds a SiteMapNode object to the collections that are maintained by the current provider. (Overrides StaticSiteMapProvider::AddNode(SiteMapNode, SiteMapNode).)
Protected methodAddProviderLinks a child site map provider to the current provider.
Public methodBuildSiteMapLoads the site map information from an XML file and builds it in memory. (Overrides StaticSiteMapProvider::BuildSiteMap().)
Protected methodClearRemoves all elements in the collections of child and parent site map nodes and site map providers that the XmlSiteMapProvider object internally tracks as part of its state. (Overrides StaticSiteMapProvider::Clear().)
Public methodDispose()Infrastructure. Notifies the file monitor of the Web.sitemap file that the XmlSiteMapProvider object no longer requires the file to be monitored.
Protected methodDispose(Boolean)Notifies the file monitor of the Web.sitemap file that the XmlSiteMapProvider object no longer requires the file to be monitored. The Dispose method takes a Boolean parameter indicating whether the method is called by user code.
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. (Inherited from SiteMapProvider.)
Public methodFindSiteMapNode(String)Retrieves a SiteMapNode object that represents the page at the specified URL. (Overrides StaticSiteMapProvider::FindSiteMapNode(String).)
Public methodFindSiteMapNodeFromKeyRetrieves a SiteMapNode object based on a specified key. (Overrides StaticSiteMapProvider::FindSiteMapNodeFromKey(String).)
Public methodGetChildNodesReturns the child nodes of the site map. (Overrides StaticSiteMapProvider::GetChildNodes(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. (Inherited from SiteMapProvider.)
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. (Inherited from SiteMapProvider.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetParentNodeReturns the parent node of the site map. (Overrides StaticSiteMapProvider::GetParentNode(SiteMapNode).)
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. (Inherited from SiteMapProvider.)
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. (Inherited from SiteMapProvider.)
Protected methodGetRootNodeCoreRetrieves the top-level node of the current site map data structure. (Overrides SiteMapProvider::GetRootNodeCore().)
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. (Inherited from SiteMapProvider.)
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. (Inherited from SiteMapProvider.)
Public methodInitializeInitializes the XmlSiteMapProvider object. The Initialize method does not actually build a site map, it only prepares the state of the XmlSiteMapProvider to do so. (Overrides SiteMapProvider::Initialize(String, NameValueCollection).)
Public methodIsAccessibleToUserRetrieves a Boolean value indicating whether the specified SiteMapNode object can be viewed by the user in the specified context. (Inherited from SiteMapProvider.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodRemoveNodeRemoves the specified SiteMapNode object from all node collections that are tracked by the provider. (Overrides StaticSiteMapProvider::RemoveNode(SiteMapNode).)
Protected methodRemoveProviderRemoves a linked child site map provider from the hierarchy for the current provider.
Protected methodResolveSiteMapNodeRaises the SiteMapResolve event. (Inherited from SiteMapProvider.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventSiteMapResolveOccurs when the CurrentNode property is called. (Inherited from SiteMapProvider.)
Top

The XmlSiteMapProvider class loads site map data from an XML file that follows a known schema. The site map data is bounded by <siteMap> tags and consists of nested <siteMapNode> tags. Two constraints are imposed by the SiteMapProvider and XmlSiteMapProvider classes on the structure of the site map data:

  • Only one root node can exist.

  • For SiteMapNode objects that specify URLs, the URLs must be unique within the scope of the provider. (For nodes that do not specify URLs, all keys must be unique.)

The following code example shows an example of an XML file that can be used with the XmlSiteMapProvider.

<siteMap>
  <siteMapNode title="RootNode" description="This is the root node of the site map. There can be only one root node." url="Page1.aspx" >
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page2.aspx">
      <siteMapNode title="ChildOfChildNode" description="SiteMapNode objects can be nested to any level." url="Page3.aspx"/>
    </siteMapNode>
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page4.aspx"/>
  </siteMapNode>
</siteMap>

The XmlSiteMapProvider is the default provider for ASP.NET and it reads XML data from a file named Web.sitemap that is located within the directory structure of the ASP.NET application. By default, the Web.sitemap file is located at the application root; however, if you want to change the name or location of the file from which the XmlSiteMapProvider loads data, you can override the default configuration in your Web.config file. By overriding the default configuration settings in your Web.config file, you can tailor the behavior of the XmlSiteMapProvider for each ASP.NET application, as necessary.

The following code example demonstrates an example Web.config file, where the XmlSiteMapProvider is still used, but a different site map file is used. Because all providers in a SiteMapProviderCollection object must be named uniquely, the one that is specified in the Web.config file uses a name other than the default but is also set as the default provider so that it will be used instead of the XmlSiteMapProvider that is specified in the default ASP.NET configuration.

NoteNote

  You can change the name of the site navigation data file, but you cannot change its extension. The XmlSiteMapProvider only reads data from files that are named with the file name extension .sitemap.

<siteMap defaultProvider="MyXmlSiteMapProvider" enabled="true">
  <providers>
    <add name="MyXmlSiteMapProvider"
      description="SiteMap provider that reads in .sitemap files."
      type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
      siteMapFile="CustomWeb.sitemap" />
  </providers>
</siteMap>
TopicLocation
How to: Programmatically Enumerate Site-Map NodesBuilding ASP .NET Web Applications
How to: Configure Multiple Site Maps and Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Filter the Nodes Retrieved by SiteMapDataSource Web Server ControlsBuilding ASP .NET Web Applications
How to: Display Site-Map Data in Non-Hierarchical Web Server ControlsBuilding ASP .NET Web Applications
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications
How to: Implement ASP.NET Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Programmatically Enumerate Site-Map NodesBuilding ASP .NET Web Applications
How to: Configure Multiple Site Maps and Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Filter the Nodes Retrieved by SiteMapDataSource Web Server ControlsBuilding ASP .NET Web Applications
How to: Display Site-Map Data in Non-Hierarchical Web Server ControlsBuilding ASP .NET Web Applications
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications
How to: Implement ASP.NET Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications in Visual Studio

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Show:
© 2014 Microsoft