SiteMap.Provider 屬性

定義

取得目前網站導覽的預設 SiteMapProvider 物件。Gets the default SiteMapProvider object for the current site map.

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

屬性值

SiteMapProvider

SiteMap 的預設網站導覽提供者。The default site map provider for the SiteMap.

例外狀況

未啟用網站導覽功能。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.

範例

下列程式碼範例示範如何 SiteMapProvider 使用靜態屬性來存取網站的預設物件 ProviderThe following code example demonstrates how to access the default SiteMapProvider object for the site by using the static Provider property.

<%@ 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>

備註

根據預設, XmlSiteMapProvider 會使用物件,並且會從位於網站根目錄的 web.config 檔案載入網站導覽資料。By default, the XmlSiteMapProvider object is used and site navigation data is loaded from the Web.sitemap file that is located in the root directory of the site. 這會在管理類別中識別,而管理類別會管理網站導覽設定和 Web.config 檔案的網站地圖設定區段。This is identified in the management classes that manage the site navigation configuration and the site map configuration section of the Web.config files. 依預設,它是類別的實例,它會使用網站地圖檔案 XmlSiteMapProvider 做為其持續性存放區。By default, it is an instance of the XmlSiteMapProvider class, which uses the Web.sitemap file as its persistent store. 不過,您可以撰寫一個可實作為抽象類別的類別,來執行您自己的網站地圖儲存體和設定配置 SiteMapProviderHowever, you can implement your own site map storage and configuration scheme by writing a class that implements the abstract SiteMapProvider class. 如需撰寫專屬提供者的詳細資訊,請參閱 SiteMapProviderFor more information on writing your own provider, see SiteMapProvider.

適用於

另請參閱