SiteMap.Providers 屬性

定義

取得名稱為 SiteMapProvider 物件的唯讀集合,這些物件可用於 SiteMap 類別。Gets a read-only collection of named SiteMapProvider objects that are available to the SiteMap class.

public:
 static property System::Web::SiteMapProviderCollection ^ Providers { System::Web::SiteMapProviderCollection ^ get(); };
public static System.Web.SiteMapProviderCollection Providers { get; }
member this.Providers : System.Web.SiteMapProviderCollection
Public Shared ReadOnly Property Providers As SiteMapProviderCollection

屬性值

SiteMapProviderCollection

名稱為 SiteMapProviderCollection 物件的 SiteMapProviderA SiteMapProviderCollection of named SiteMapProvider objects.

例外狀況

未啟用網站導覽功能。The site map feature is not enabled.

組態中指定的預設提供者不存在。The default provider specified in the configuration does not exist.

只有低度信任 (含) 以上的模式才有支援這個功能。The feature is supported only when running in Low trust or higher.

範例

下列程式碼範例示範如何 Providers 從類別取出集合 SiteMap ,然後逐一查看該集合。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>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
Private Sub Page_Load(Sender As Object, E As EventArgs)

    ' 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>")

    Dim sitemapnode As SiteMapNode
    For Each sitemapnode In SiteMap.RootNode.ChildNodes
        ' Iterate through the ChildNodes SiteMapNodesCollection
        ' maintained by the RootNode.
        Response.Write(sitemapnode.Url & "<BR>" )
    Next

    Dim providers As IDictionaryEnumerator = SiteMap.Providers.GetEnumerator()
    While (providers.MoveNext())
        Response.Write(providers.Current)
        Response.Write("&nbsp;&nbsp;&nbsp;")
        Response.Write("<BR>")
    End While
End Sub ' Page_Load

</SCRIPT>

如果您的網站已設定的預設提供者不只,您將會看到每個提供者顯示。If you have more than just the default provider configured for your site, you will see each provider displayed. 例如,如果您使用範例 Microsoft Access provider (查看 StaticSiteMapProvider) ,您會看到下列輸出: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  

備註

集合中所列的網站地圖提供者是設定階層中所指定的網站地圖提供者, Providers 用來初始化 SiteMap 類別。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. 只有屬性) 所識別的預設提供者 (Provider 保證會在初始化期間使用,而 SiteMap 集合中的提供者則 Providers 表示它是在設定中指定,而且可在初始化期間使用。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.

適用於

另請參閱