語言

XmlSiteMapProvider.Initialize(String, NameValueCollection) 方法

定義

初始化 XmlSiteMapProvider 物件。 這個 Initialize(String, NameValueCollection) 方法其實並不是建立一個網站地圖,它只是準備要建立網站的狀態 XmlSiteMapProvider 。

public:
 override void Initialize(System::String ^ name, System::Collections::Specialized::NameValueCollection ^ attributes);
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection attributes);
override this.Initialize : string * System.Collections.Specialized.NameValueCollection -> unit
Public Overrides Sub Initialize (name As String, attributes As NameValueCollection)

參數

name
String

初始 XmlSiteMapProvider 化。

attributes
NameValueCollection

NameValueCollection A 可包含額外屬性以協助初始化 name。 這些屬性會從 XmlSiteMapProvider Web.config 檔案中的設定讀取。

例外狀況

初始 XmlSiteMapProvider 化不只一次。

A SiteMapNode 使用實體路徑來參考網站地圖檔案。

-或-

在嘗試解析該 siteMapFile 屬性所提供的虛擬路徑時發生錯誤。

範例

以下程式碼範例示範如何建立該類別的新實例 XmlSiteMapProvider ,並初始化以從 XML 資料建立站點地圖。

<%@ Page Language="c#" %>
<SCRIPT runat="server">
 private void Page_Load(object sender, System.EventArgs e) {
     // Create an instance of the XmlSiteMapProvider class.
     XmlSiteMapProvider testXmlProvider = new XmlSiteMapProvider();
     NameValueCollection providerAttributes = new NameValueCollection(1);
     providerAttributes.Add("siteMapFile","test.sitemap");

     // Initialize the provider with a provider name and file name.
     testXmlProvider.Initialize("testProvider", providerAttributes);

     // Call the BuildSiteMap to load the site map information into memory.
     testXmlProvider.BuildSiteMap();

     // Prints "/myvirtualdirectory/WebForm1.aspx"
     Response.Write(testXmlProvider.RootNode.Url + "<BR>");

     // Prints "/myvirtualdirectory/WebForm2.aspx"
     Response.Write(testXmlProvider.CurrentNode.Url + "<BR>");
 }
 </SCRIPT>

前述的程式碼範例使用位於 ASP.NET 應用程式虛擬根節點的 XML 檔案。 檔案格式如下:

<siteMap>
  <siteMapNode title="RootNode" description="The root page." url="WebForm1.aspx">
    <siteMapNode title="CurrentNode" description="Some sub page." url="WebForm2.aspx"/>
  </siteMapNode>
</siteMap>

備註

該 XmlSiteMapProvider 類別會覆寫繼 Initialize 承的方法,將多個屬性(如 和 siteMapFiledescription 屬性)套用到集合中 attributes 。

適用於

另請參閱