XmlSiteMapProvider.Initialize(String, NameValueCollection) 方法


初始化 XmlSiteMapProvider 物件。Initializes the XmlSiteMapProvider object. Initialize(String, NameValueCollection) 方法不會實際建置網站地圖,而只會準備 XmlSiteMapProvider 的狀態以執行這項作業。The Initialize(String, NameValueCollection) method does not actually build a site map, it only prepares the state of the XmlSiteMapProvider to do so.

 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)



要初始化的 XmlSiteMapProviderThe XmlSiteMapProvider to initialize.


NameValueCollection,可以包含用來協助初始化 name 的其他屬性。A NameValueCollection that can contain additional attributes to help initialize name. 系統會從 Web.config 檔中的 XmlSiteMapProvider 組態讀取這些屬性。These attributes are read from the XmlSiteMapProvider configuration in the Web.config file.


XmlSiteMapProvider 已多次初始化。The XmlSiteMapProvider is initialized more than once.

SiteMapNode 使用實體路徑參考網站地圖檔案。A SiteMapNode used a physical path to reference a site map file.

-或--or- 嘗試剖析提供給 siteMapFile 屬性的虛擬路徑時發生錯誤。An error occurred while attempting to parse the virtual path supplied for the siteMapFile attribute.


下列程式碼範例示範如何建立類別的新實例 XmlSiteMapProvider ,並將其初始化,以從 XML 資料建立網站地圖。The following code example demonstrates how to create a new instance of the XmlSiteMapProvider class and initialize it to build a site map from XML data.

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

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

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

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

上述程式碼範例使用的 XML 檔案位於 ASP.NET 應用程式的虛擬根目錄中。The preceding code example uses an XML file that is located in the virtual root of the ASP.NET application. 檔案的格式如下:The file has the following format:

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


XmlSiteMapProvider類別會覆寫繼承的方法,將 Initialize 數個屬性(例如 siteMapFile 和屬性)套用 descriptionattributes 集合。The XmlSiteMapProvider class overrides the inherited Initialize method to apply several attributes, such as the siteMapFile and description attributes, to the attributes collection.