XmlSiteMapProvider 類別

定義

XmlSiteMapProvider 類別衍生自 SiteMapProvider 類別,而且是 ASP.NET 的預設網站地圖提供者。The XmlSiteMapProvider class is derived from the SiteMapProvider class and is the default site map provider for ASP.NET. XmlSiteMapProvider 類別會從副檔名為 .sitemap 的 XML 檔案產生網站地圖樹狀結構。The XmlSiteMapProvider class generates site map trees from XML files with the file name extension .sitemap.

public ref class XmlSiteMapProvider : System::Web::StaticSiteMapProvider, IDisposable
public class XmlSiteMapProvider : System.Web.StaticSiteMapProvider, IDisposable
type XmlSiteMapProvider = class
    inherit StaticSiteMapProvider
    interface IDisposable
Public Class XmlSiteMapProvider
Inherits StaticSiteMapProvider
Implements IDisposable
繼承
實作

備註

XmlSiteMapProvider類別會從遵循已知架構的 XML 檔案載入網站地圖資料。The XmlSiteMapProvider class loads site map data from an XML file that follows a known schema. 網站地圖資料是由<siteMap>標記所限定, 並由嵌套<siteMapNode>標記所組成。The site map data is bounded by <siteMap> tags and consists of nested <siteMapNode> tags. 網站對應資料結構上的SiteMapProviderXmlSiteMapProvider類別會加諸兩個條件約束:Two constraints are imposed by the SiteMapProvider and XmlSiteMapProvider classes on the structure of the site map data:

  • 只有一個根節點可以存在。Only one root node can exist.

  • 對於SiteMapNode指定 url 的物件, url 在提供者的範圍內必須是唯一的。For SiteMapNode objects that specify URLs, the URLs must be unique within the scope of the provider. (對於未指定 Url 的節點, 所有索引鍵都必須是唯一的)。(For nodes that do not specify URLs, all keys must be unique.)

下列程式碼範例顯示可與XmlSiteMapProvider搭配使用的 XML 檔案範例。The following code example shows an example of an XML file that can be used with the XmlSiteMapProvider.

<siteMap>  
  <siteMapNode title="RootNode" description="This is the root node of the site map. There can be only one root node." url="Page1.aspx" >  
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page2.aspx">  
      <siteMapNode title="ChildOfChildNode" description="SiteMapNode objects can be nested to any level." url="Page3.aspx"/>  
    </siteMapNode>  
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page4.aspx"/>  
  </siteMapNode>  
</siteMap>  

XmlSiteMapProvider是 ASP.NET 的預設提供者, 它會從 ASP.NET 應用程式的目錄結構中名為 web.config 的檔案讀取 XML 資料。The XmlSiteMapProvider is the default provider for ASP.NET and it reads XML data from a file named Web.sitemap that is located within the directory structure of the ASP.NET application. 根據預設, web.sitemap 檔案位於應用程式根目錄。不過, 如果您想要變更用來XmlSiteMapProvider載入資料之檔案的名稱或位置, 您可以覆寫 web.config 檔案中的預設設定。By default, the Web.sitemap file is located at the application root; however, if you want to change the name or location of the file from which the XmlSiteMapProvider loads data, you can override the default configuration in your Web.config file. 藉由覆寫 web.config 檔案中的預設設定, 您可以視需要量身打造每個 ASP.NET XmlSiteMapProvider應用程式的行為。By overriding the default configuration settings in your Web.config file, you can tailor the behavior of the XmlSiteMapProvider for each ASP.NET application, as necessary.

下列程式碼範例示範 web.config 檔案的XmlSiteMapProvider範例, 其中仍會使用, 但使用不同的網站地圖檔案。The following code example demonstrates an example Web.config file, where the XmlSiteMapProvider is still used, but a different site map file is used. 因為SiteMapProviderCollection物件中的所有提供者都必須以唯一的方式命名, 所以 web.config 檔案中指定的名稱會使用預設值, 但也會設定為預設提供者, 因此將會使用它, 而不是在XmlSiteMapProvider第一次中指定的e 預設 ASP.NET 設定。Because all providers in a SiteMapProviderCollection object must be named uniquely, the one that is specified in the Web.config file uses a name other than the default but is also set as the default provider so that it will be used instead of the XmlSiteMapProvider that is specified in the default ASP.NET configuration.

注意

您可以變更網站導覽資料檔案的名稱, 但無法變更其延伸模組。You can change the name of the site navigation data file, but you cannot change its extension. XmlSiteMapProvider只會從以副檔名. 網站地圖命名的檔案中讀取資料。The XmlSiteMapProvider only reads data from files that are named with the file name extension .sitemap.

<siteMap defaultProvider="MyXmlSiteMapProvider" enabled="true">  
  <providers>  
    <add name="MyXmlSiteMapProvider"  
      description="SiteMap provider that reads in .sitemap files."  
      type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"  
      siteMapFile="CustomWeb.sitemap" />  
  </providers>  
</siteMap>  

建構函式

XmlSiteMapProvider()

建立 XmlSiteMapProvider 類別的未命名新執行個體。Creates a new, unnamed, instance of the XmlSiteMapProvider class.

屬性

CurrentNode

取得代表目前所要求頁面的 SiteMapNode 物件。Gets the SiteMapNode object that represents the currently requested page.

Description

取得簡短、易讀的描述,適合顯示在管理工具或其他使用者介面 (UI) 中。Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(繼承來源 ProviderBase)
EnableLocalization

取得或設定布林值,指出是否傳回 SiteMapNode 屬性的當地語系化值。Gets or sets a Boolean value indicating whether localized values of SiteMapNode attributes are returned.

(繼承來源 SiteMapProvider)
Name

取得用來在設定期間代表提供者的易記名稱。Gets the friendly name used to refer to the provider during configuration.

(繼承來源 ProviderBase)
ParentProvider

取得或設定目前提供者的父代 SiteMapProvider 物件。Gets or sets the parent SiteMapProvider object of the current provider.

(繼承來源 SiteMapProvider)
ResourceKey

取得或設定用來當地語系化 SiteMapNode 屬性的資源索引鍵。Get or sets the resource key that is used for localizing SiteMapNode attributes.

(繼承來源 SiteMapProvider)
RootNode

取得網站地圖的根節點。Gets the root node of the site map.

RootProvider

取得目前提供者階層架構中的根 SiteMapProvider 物件。Gets the root SiteMapProvider object in the current provider hierarchy.

(繼承來源 SiteMapProvider)
SecurityTrimmingEnabled

取得布林值,指出網站導覽提供者是否根據使用者的角色篩選網站導覽節點。Gets a Boolean value indicating whether a site map provider filters site map nodes based on a user's role.

(繼承來源 SiteMapProvider)

方法

AddNode(SiteMapNode)

SiteMapNode 物件加入至網站導覽提供者所維護的節點集合。Adds a SiteMapNode object to the node collection that is maintained by the site map provider.

(繼承來源 SiteMapProvider)
AddNode(SiteMapNode, SiteMapNode)

SiteMapNode 物件新增至目前提供者所維護的集合中。Adds a SiteMapNode object to the collections that are maintained by the current provider.

AddProvider(String, SiteMapNode)

將子網站地圖提供者連結至目前的提供者。Links a child site map provider to the current provider.

BuildSiteMap()

從 XML 檔案載入網站地圖資訊,並將其建置在記憶體中。Loads the site map information from an XML file and builds it in memory.

Clear()

移除子系和父代網站地圖節點及網站地圖提供者集合中的所有項目;XmlSiteMapProvider 物件會在內部追蹤其狀態時一併追蹤這些集合。Removes all elements in the collections of child and parent site map nodes and site map providers that the XmlSiteMapProvider object internally tracks as part of its state.

Dispose()

告知 Web.sitemap 檔的檔案監視器,XmlSiteMapProvider 物件不再需要監視該檔案。Notifies the file monitor of the Web.sitemap file that the XmlSiteMapProvider object no longer requires the file to be monitored.

Dispose(Boolean)

告知 Web.sitemap 檔的檔案監視器,XmlSiteMapProvider 物件不再需要監視該檔案。Notifies the file monitor of the Web.sitemap file that the XmlSiteMapProvider object no longer requires the file to be monitored. Dispose(Boolean) 方法會使用布林參數,指出方法是否由使用者程式碼呼叫。The Dispose(Boolean) method takes a Boolean parameter indicating whether the method is called by user code.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
FindSiteMapNode(HttpContext)

使用指定的 SiteMapNode 物件,擷取表示目前所要求之網頁的 HttpContext 物件。Retrieves a SiteMapNode object that represents the currently requested page using the specified HttpContext object.

(繼承來源 SiteMapProvider)
FindSiteMapNode(String)

擷取 SiteMapNode 物件,其代表位於指定 URL 的頁面。Retrieves a SiteMapNode object that represents the page at the specified URL.

FindSiteMapNodeFromKey(String)

根據指定的索引鍵,擷取 SiteMapNode 物件。Retrieves a SiteMapNode object based on a specified key.

GetChildNodes(SiteMapNode)

傳回網站地圖的子節點。Returns the child nodes of the site map.

GetCurrentNodeAndHintAncestorNodes(Int32)

當擷取目前所要求之網頁的節點,以及擷取目前網頁的父代和祖系網站導覽節點時,提供網站導覽提供者的最佳化查閱方法。Provides an optimized lookup method for site map providers when retrieving the node for the currently requested page and fetching the parent and ancestor site map nodes for the current page.

(繼承來源 SiteMapProvider)
GetCurrentNodeAndHintNeighborhoodNodes(Int32, Int32)

當擷取目前所要求之網頁的節點,以及擷取目前節點附近的網站導覽節點時,提供網站導覽提供者的最佳化查閱方法。Provides an optimized lookup method for site map providers when retrieving the node for the currently requested page and fetching the site map nodes in the proximity of the current node.

(繼承來源 SiteMapProvider)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetParentNode(SiteMapNode)

傳回網站地圖的父代節點。Returns the parent node of the site map.

GetParentNodeRelativeToCurrentNodeAndHintDownFromParent(Int32, Int32)

當擷取目前所要求之網頁的祖系節點,以及擷取祖系的子代節點時,提供網站導覽提供者的最佳化查閱方法。Provides an optimized lookup method for site map providers when retrieving an ancestor node for the currently requested page and fetching the descendant nodes for the ancestor.

(繼承來源 SiteMapProvider)
GetParentNodeRelativeToNodeAndHintDownFromParent(SiteMapNode, Int32, Int32)

當擷取指定 SiteMapNode 物件的祖系節點,以及擷取其子節點時,提供網站導覽提供者的最佳化查閱方法。Provides an optimized lookup method for site map providers when retrieving an ancestor node for the specified SiteMapNode object and fetching its child nodes.

(繼承來源 SiteMapProvider)
GetRootNodeCore()

擷取目前網站地圖資料結構的最上層節點。Retrieves the top-level node of the current site map data structure.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
HintAncestorNodes(SiteMapNode, Int32)

提供方法,讓網站導覽提供者可以覆寫,以最佳化方式擷取相對於指定 SiteMapNode 物件的一或多個層級之父代和祖系節點。Provides a method that site map providers can override to perform an optimized retrieval of one or more levels of parent and ancestor nodes, relative to the specified SiteMapNode object.

(繼承來源 SiteMapProvider)
HintNeighborhoodNodes(SiteMapNode, Int32, Int32)

提供方法,讓網站導覽提供者可以覆寫,以最佳化方式擷取指定節點附近找到的節點。Provides a method that site map providers can override to perform an optimized retrieval of nodes found in the proximity of the specified node.

(繼承來源 SiteMapProvider)
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.

IsAccessibleToUser(HttpContext, SiteMapNode)

擷取布林值,指出在指定內容中使用者是否可以檢視指定的 SiteMapNode 物件。Retrieves a Boolean value indicating whether the specified SiteMapNode object can be viewed by the user in the specified context.

(繼承來源 SiteMapProvider)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
RemoveNode(SiteMapNode)

從提供者追蹤的所有節點集合中,移除指定的 SiteMapNode 物件。Removes the specified SiteMapNode object from all node collections that are tracked by the provider.

RemoveProvider(String)

從目前提供者的階層架構,移除連結的子網站地圖提供者。Removes a linked child site map provider from the hierarchy for the current provider.

ResolveSiteMapNode(HttpContext)

引發 SiteMapResolve 事件。Raises the SiteMapResolve event.

(繼承來源 SiteMapProvider)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

事件

SiteMapResolve

呼叫 CurrentNode 屬性時發生。Occurs when the CurrentNode property is called.

(繼承來源 SiteMapProvider)

適用於

另請參閱