Export (0) Print
Expand All

SiteMap.Providers Property

Gets a read-only collection of named SiteMapProvider objects that are available to the SiteMap class.

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

public static SiteMapProviderCollection Providers { get; }

ExceptionCondition
InvalidOperationException

The site map feature is not enabled.

ConfigurationErrorsException

The default provider specified in the configuration does not exist.

HttpException

The feature is supported only when running in Low trust or higher.

The site map providers that are listed in the Providers collection are those that are specified in the configuration hierarchy to initialize the SiteMap class. Only the default provider (identified by the Provider property) is guaranteed to be used by the SiteMap during initialization; the presence of a provider in the Providers collection means that it was specified in the configuration and was available during initialization.

The following code example demonstrates how to retrieve the Providers collection from the SiteMap class, and then iterate through it.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
    // Navigate the SiteMap built by the default SiteMapProvider.
    Response.Write(SiteMap.RootNode.ToString() + "<BR>");

    Response.Write(SiteMap.RootNode.Url + "<BR>");
    Response.Write(SiteMap.RootNode.Title + "<BR>");

    foreach (SiteMapNode sitemapnode in SiteMap.RootNode.ChildNodes)
    {
        // Iterate through the ChildNodes SiteMapNodesCollection
        // maintained by the RootNode.
        Response.Write(sitemapnode.Url + "<BR>" );
    }

    IEnumerator providers = SiteMap.Providers.GetEnumerator();
    while (providers.MoveNext())
    {
        Response.Write(providers.Current);
        Response.Write("&nbsp;&nbsp;&nbsp;");
        Response.Write("<BR>");
    }
}
</SCRIPT>

If you have more than just the default provider configured for your site, you will see each provider displayed. For example, if you are using the sample Microsoft Access provider (see StaticSiteMapProvider), you see the following output:

XmlSiteMapProvider   System.Web.XmlSiteMapProvider
AccessSiteMapProvider   Samples.AspNet.AccessSiteMapProvider

.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.

Show:
© 2014 Microsoft