XmlSiteMapProvider XmlSiteMapProvider XmlSiteMapProvider XmlSiteMapProvider Class

定義

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

下列程式碼範例示範 XML 檔案,可以搭配XmlSiteMapProviderThe 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.sitemap 檔案讀取 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 檔案中,您可以自訂的行為XmlSiteMapProvider每個 ASP.NET 應用程式,視。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只會從命名的檔案副檔名為.sitemap 檔案讀取資料。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() XmlSiteMapProvider() XmlSiteMapProvider()

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

屬性

CurrentNode CurrentNode CurrentNode CurrentNode

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

Description Description Description Description

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

(Inherited from ProviderBase)
EnableLocalization EnableLocalization EnableLocalization EnableLocalization

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

(Inherited from SiteMapProvider)
Name Name Name Name

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

(Inherited from ProviderBase)
ParentProvider ParentProvider ParentProvider ParentProvider

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

(Inherited from SiteMapProvider)
ResourceKey ResourceKey ResourceKey ResourceKey

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

(Inherited from SiteMapProvider)
RootNode RootNode RootNode RootNode

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

RootProvider RootProvider RootProvider RootProvider

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

(Inherited from SiteMapProvider)
SecurityTrimmingEnabled SecurityTrimmingEnabled SecurityTrimmingEnabled SecurityTrimmingEnabled

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

(Inherited from SiteMapProvider)

方法

AddNode(SiteMapNode) AddNode(SiteMapNode) AddNode(SiteMapNode) AddNode(SiteMapNode)

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

(Inherited from SiteMapProvider)
AddNode(SiteMapNode, SiteMapNode) AddNode(SiteMapNode, SiteMapNode) AddNode(SiteMapNode, SiteMapNode) AddNode(SiteMapNode, SiteMapNode)

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

AddProvider(String, SiteMapNode) AddProvider(String, SiteMapNode) AddProvider(String, SiteMapNode) AddProvider(String, SiteMapNode)

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

BuildSiteMap() BuildSiteMap() BuildSiteMap() BuildSiteMap()

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

Clear() Clear() Clear() 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() Dispose() Dispose() 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) Dispose(Boolean) Dispose(Boolean) 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) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
FindSiteMapNode(HttpContext) FindSiteMapNode(HttpContext) FindSiteMapNode(HttpContext) FindSiteMapNode(HttpContext)

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

(Inherited from SiteMapProvider)
FindSiteMapNode(String) FindSiteMapNode(String) FindSiteMapNode(String) FindSiteMapNode(String)

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

FindSiteMapNodeFromKey(String) FindSiteMapNodeFromKey(String) FindSiteMapNodeFromKey(String) FindSiteMapNodeFromKey(String)

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

GetChildNodes(SiteMapNode) GetChildNodes(SiteMapNode) GetChildNodes(SiteMapNode) GetChildNodes(SiteMapNode)

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

GetCurrentNodeAndHintAncestorNodes(Int32) GetCurrentNodeAndHintAncestorNodes(Int32) GetCurrentNodeAndHintAncestorNodes(Int32) 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.

(Inherited from SiteMapProvider)
GetCurrentNodeAndHintNeighborhoodNodes(Int32, Int32) GetCurrentNodeAndHintNeighborhoodNodes(Int32, Int32) GetCurrentNodeAndHintNeighborhoodNodes(Int32, Int32) 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.

(Inherited from SiteMapProvider)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetParentNode(SiteMapNode) GetParentNode(SiteMapNode) GetParentNode(SiteMapNode) GetParentNode(SiteMapNode)

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

GetParentNodeRelativeToCurrentNodeAndHintDownFromParent(Int32, Int32) GetParentNodeRelativeToCurrentNodeAndHintDownFromParent(Int32, Int32) GetParentNodeRelativeToCurrentNodeAndHintDownFromParent(Int32, Int32) 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.

(Inherited from SiteMapProvider)
GetParentNodeRelativeToNodeAndHintDownFromParent(SiteMapNode, Int32, Int32) GetParentNodeRelativeToNodeAndHintDownFromParent(SiteMapNode, Int32, Int32) GetParentNodeRelativeToNodeAndHintDownFromParent(SiteMapNode, Int32, Int32) 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.

(Inherited from SiteMapProvider)
GetRootNodeCore() GetRootNodeCore() GetRootNodeCore() GetRootNodeCore()

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

GetType() GetType() GetType() GetType()

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

(Inherited from Object)
HintAncestorNodes(SiteMapNode, Int32) HintAncestorNodes(SiteMapNode, Int32) HintAncestorNodes(SiteMapNode, Int32) 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.

(Inherited from SiteMapProvider)
HintNeighborhoodNodes(SiteMapNode, Int32, Int32) HintNeighborhoodNodes(SiteMapNode, Int32, Int32) HintNeighborhoodNodes(SiteMapNode, Int32, Int32) 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.

(Inherited from SiteMapProvider)
Initialize(String, NameValueCollection) Initialize(String, NameValueCollection) Initialize(String, NameValueCollection) 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) IsAccessibleToUser(HttpContext, SiteMapNode) IsAccessibleToUser(HttpContext, SiteMapNode) IsAccessibleToUser(HttpContext, SiteMapNode)

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

(Inherited from SiteMapProvider)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
RemoveNode(SiteMapNode) RemoveNode(SiteMapNode) RemoveNode(SiteMapNode) RemoveNode(SiteMapNode)

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

RemoveProvider(String) RemoveProvider(String) RemoveProvider(String) RemoveProvider(String)

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

ResolveSiteMapNode(HttpContext) ResolveSiteMapNode(HttpContext) ResolveSiteMapNode(HttpContext) ResolveSiteMapNode(HttpContext)

引發 SiteMapResolve 事件。Raises the SiteMapResolve event.

(Inherited from SiteMapProvider)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)

事件

SiteMapResolve SiteMapResolve SiteMapResolve SiteMapResolve

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

(Inherited from SiteMapProvider)

適用於

另請參閱