SiteMap 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
SiteMap 類別是存放於記憶體之網站巡覽結構的表現方式,由一或多個網站導覽提供者所提供。 此類別無法獲得繼承。
public ref class SiteMap abstract sealed
public static class SiteMap
type SiteMap = class
Public Class SiteMap
- 繼承
-
SiteMap
範例
本節包含兩個程式碼範例。 第一個程式碼範例示範如何在Web.config檔案中宣告網站地圖提供者。 第二個 SiteMap 程式碼範例示範如何使用 物件。
下列程式碼範例是Web.config組態區段,示範如何將 XmlSiteMapProvider 物件宣告為預設 SiteMapProvider 物件。
<siteMap defaultProvider="MyXmlSiteMapProvider" enabled="true">
<providers>
<add name="MyXmlSiteMapProvider"
description="The site map provider that reads in the .sitemap XML files."
type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
siteMapFile="my.sitemap" />
</providers>
</siteMap>
下列程式碼範例示範如何 SiteMap 藉由存取物件的靜態成員來顯示 和 CurrentNode 屬性的相關資訊 RootNode 。 將它與 控制項所轉譯的 SiteMapPath 輸出進行比較。
<%@ 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)
{
// Examine the CurrentNode, and navigate the SiteMap relative to it.
Response.Write(SiteMap.CurrentNode.Title + "<br />");
Response.Write("<font COLOR='red'>" + SiteMap.CurrentNode.Url + "</font><br />");
// What nodes are children of the CurrentNode?
if (SiteMap.CurrentNode.HasChildNodes) {
IEnumerator childNodesEnumerator = SiteMap.CurrentNode.ChildNodes.GetEnumerator();
while (childNodesEnumerator.MoveNext()) {
// Prints the Title of each node.
Response.Write(childNodesEnumerator.Current.ToString() + "<br />");
}
}
Response.Write("<hr />");
// Examine the RootNode, and navigate the SiteMap relative to it.
Response.Write(SiteMap.RootNode.Title + "<br />");
Response.Write(SiteMap.RootNode.Url + "<br />");
// What nodes are children of the RootNode?
if (SiteMap.RootNode.HasChildNodes) {
IEnumerator rootNodesChildrenEnumerator = SiteMap.RootNode.ChildNodes.GetEnumerator();
while (rootNodesChildrenEnumerator.MoveNext()) {
// Prints the Title of each node.
Response.Write(rootNodesChildrenEnumerator.Current.ToString() + "<br />");
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:SiteMapPath
runat="server"
ID="SiteMapPath1"
ShowToolTips="false"/>
</form>
</body>
</html>
<%@ 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 System.EventArgs)
' Examine the CurrentNode, and navigate the SiteMap relative to it.
Response.Write(SiteMap.CurrentNode.Title & "<br />")
Response.Write("<font COLOR='red'>" & SiteMap.CurrentNode.Url & "</font><br />")
' What nodes are children of the CurrentNode?
If (SiteMap.CurrentNode.HasChildNodes) Then
Dim childNodesEnumerator As IEnumerator = SiteMap.CurrentNode.ChildNodes.GetEnumerator()
While (childNodesEnumerator.MoveNext())
' Prints the Title of each node.
Response.Write(childNodesEnumerator.Current.ToString() & "<br />")
End While
End If
Response.Write("<hr />")
' Examine the RootNode, and navigate the SiteMap relative to it.
Response.Write(SiteMap.RootNode.Title & "<br />")
Response.Write(SiteMap.RootNode.Url & "<br />")
' What nodes are children of the RootNode?
If (SiteMap.RootNode.HasChildNodes) Then
Dim rootNodesChildrenEnumerator As IEnumerator = SiteMap.RootNode.ChildNodes.GetEnumerator()
While (rootNodesChildrenEnumerator.MoveNext())
' Prints the Title of each node.
Response.Write(rootNodesChildrenEnumerator.Current.ToString() & "<br />")
End While
End If
End Sub ' Page_Load
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:SiteMapPath
runat="server"
ID="SiteMapPath1"
ShowToolTips="false"/>
</form>
</body>
</html>
備註
網站地圖會與 、 SiteMapPath 和其他控制項搭配 SiteMapDataSource 使用,以呈現有效的流覽介面,讓使用者流覽網站。 SiteMap物件是 ASP.NET 網站導覽基礎結構的元件,可讓您使用導覽和 SiteMapDataSource 控制項,存取頁面和控制項開發人員的唯讀網站地圖資訊。 ASP.NET 網站導覽基礎結構的其他元件包括 SiteMapProvider 和 XmlSiteMapProvider 類別、Web.sitemap 檔案,以及使用 SiteMap 類別的各種控制項,例如 SiteMapPath 控制項,以轉譯內容和功能表。
SiteMap有數個函式:
它提供網站導覽階層的根節點, (只能有一個根節點) 。
它會識別哪個網站地圖提供者是主體或預設的提供者。
它會追蹤用來建立 SiteMap 的所有提供者物件。
基本上, SiteMap 是 物件的階層式集合容器 SiteMapNode 。 不過, SiteMap 不會維護節點之間的關聯性,而是會將此專案委派給網站地圖提供者。 SiteMap做為網站導覽資訊的介面, (這些網站地圖提供者所持有的物件) 形式 SiteMapNode 。 它會追蹤可從中存取網站導覽資料的提供者,並公開其 Providers 集合。 只要提供者擴充 SiteMapProvider 抽象類別,就可以以任何方式儲存其網站地圖資訊, SiteMap 就可以從中成功初始化類別。
類別的預設提供者 SiteMap 是 XmlSiteMapProvider 類別,其適用于 XML 組態檔 Web.sitemap。 不過,您可以撰寫自己的 SiteMapProvider 物件,並用它來初始化網站的網站地圖。 如需自訂網站地圖提供者的範例,請參閱 SiteMapProvider 。
會指定管理網站導覽設定的預設網站地圖組態。 您可以選擇撰寫自己的網站地圖提供者,在Web.config檔案中覆寫此組態。
類別 SiteMap 僅提供靜態成員的效能,而且可以隨時從 Web Form 或 Web 服務器控制項存取指定網站。
屬性
CurrentNode |
取得 SiteMapNode 控制項,表示目前要求的網頁。 |
Enabled |
取得布林值,指出 Web.config 檔案中是否已指定網站導覽提供者,以及網站導覽提供者是否已啟用。 |
Provider |
取得目前網站導覽的預設 SiteMapProvider 物件。 |
Providers |
取得名稱為 SiteMapProvider 物件的唯讀集合,這些物件可用於 SiteMap 類別。 |
RootNode |
取得 SiteMapNode 物件,表示網站巡覽結構最上層網頁。 |
事件
SiteMapResolve |
當存取 CurrentNode 屬性時發生。 |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應