SiteMapNode 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化类的新实例 SiteMapNode 并将其与指定的 SiteMapProvider 对象相关联。
重载
| 名称 | 说明 |
|---|---|
| SiteMapNode(SiteMapProvider, String) |
使用指定的 |
| SiteMapNode(SiteMapProvider, String, String) |
使用指定的 URL 初始化类的新实例 SiteMapNode 、标识 |
| SiteMapNode(SiteMapProvider, String, String, String) |
使用指定的 URL 初始化类的新实例 SiteMapNode ,该 |
| SiteMapNode(SiteMapProvider, String, String, String, String) |
使用指定的 URL 初始化类的新实例 SiteMapNode 、用于 |
| SiteMapNode(SiteMapProvider, String, String, String, String, IList, NameValueCollection, NameValueCollection, String) |
使用用于管理节点、URL、标题、说明、角色、其他属性以及用于本地化的显式和隐式资源密钥的指定站点地图提供程序初始化类的新实例 SiteMapNode 。 |
SiteMapNode(SiteMapProvider, String)
使用指定的key实例初始化类的新实例SiteMapNode,以标识节点所表示的页面以及管理节点的站点地图提供程序。
public:
SiteMapNode(System::Web::SiteMapProvider ^ provider, System::String ^ key);
public SiteMapNode(System.Web.SiteMapProvider provider, string key);
new System.Web.SiteMapNode : System.Web.SiteMapProvider * string -> System.Web.SiteMapNode
Public Sub New (provider As SiteMapProvider, key As String)
参数
- provider
- SiteMapProvider
与 SiteMapProvider 节点关联的节点。
- key
- String
提供程序特定的查找键。
例外
注解
该 XmlSiteMapProvider 类是 ASP.NET 的默认 SiteMapProvider 提供程序实现, SiteMapNode.Url 如果为节点提供属性作为查找键(如果未提供 URL,则为节点生成跟踪标识符)。 因此,提供 URL 并由提供程序使用XmlSiteMapProvider的任何SiteMapNode控件都必须在提供程序范围内具有唯一 URL。
适用于
SiteMapNode(SiteMapProvider, String, String)
使用指定的 URL 初始化类的新实例 SiteMapNode 、标识 key 节点所表示的页面以及管理节点的站点地图提供程序。
public:
SiteMapNode(System::Web::SiteMapProvider ^ provider, System::String ^ key, System::String ^ url);
public SiteMapNode(System.Web.SiteMapProvider provider, string key, string url);
new System.Web.SiteMapNode : System.Web.SiteMapProvider * string * string -> System.Web.SiteMapNode
Public Sub New (provider As SiteMapProvider, key As String, url As String)
参数
- provider
- SiteMapProvider
与 SiteMapProvider 节点关联的节点。
- key
- String
提供程序特定的查找键。
- url
- String
节点在站点中表示的页面的 URL。
例外
示例
下面的代码示例演示如何使用 SiteMapNodeCollection 构造函数创建新 SiteMapNodeCollection 集合,然后使用该方法向其 Add 添加元素。
// The LoadSiteMapData() method loads site navigation
// data from persistent storage into a DataTable.
DataTable siteMap = LoadSiteMapData();
// Create a SiteMapNodeCollection.
SiteMapNodeCollection nodes = new SiteMapNodeCollection();
// Create a SiteMapNode and add it to the collection.
SiteMapNode tempNode;
DataRow row;
int index = 0;
while (index < siteMap.Rows.Count)
{
row = siteMap.Rows[index];
// Create a node based on the data in the DataRow.
tempNode = new SiteMapNode(SiteMap.Provider,
row["Key"].ToString(),
row["Url"].ToString());
// Add the node to the collection.
nodes.Add(tempNode);
++index;
}
' The LoadSiteMapData() Function loads site navigation
' data from persistent storage into a DataTable.
Dim siteMapData As DataTable
siteMapData = LoadSiteMapData()
' Create a SiteMapNodeCollection.
Dim nodes As New SiteMapNodeCollection()
' Create a SiteMapNode and add it to the collection.
Dim tempNode As SiteMapNode
Dim row As DataRow
Dim index As Integer
index = 0
While (index < siteMapData.Rows.Count)
row = siteMapData.Rows(index)
' Create a node based on the data in the DataRow.
tempNode = New SiteMapNode(SiteMap.Provider, row("Key").ToString(), row("Url").ToString())
' Add the node to the collection.
nodes.Add(tempNode)
index = index + 1
End While
注解
该 XmlSiteMapProvider 类是 ASP.NET 的默认 SiteMapProvider 提供程序实现, SiteMapNode.Url 如果为节点提供属性作为查找键(如果未提供 URL,则为节点生成跟踪标识符)。 因此, SiteMapNode 提供 URL 且由 XmlSiteMapProvider 提供程序范围内必须具有唯一 URL 的任何对象。
适用于
SiteMapNode(SiteMapProvider, String, String, String)
使用指定的 URL 初始化类的新实例 SiteMapNode ,该 key URL 用于标识节点所表示的页面、标题以及管理节点的站点地图提供程序。
public:
SiteMapNode(System::Web::SiteMapProvider ^ provider, System::String ^ key, System::String ^ url, System::String ^ title);
public SiteMapNode(System.Web.SiteMapProvider provider, string key, string url, string title);
new System.Web.SiteMapNode : System.Web.SiteMapProvider * string * string * string -> System.Web.SiteMapNode
Public Sub New (provider As SiteMapProvider, key As String, url As String, title As String)
参数
- provider
- SiteMapProvider
与 SiteMapProvider 节点关联的节点。
- key
- String
提供程序特定的查找键。
- url
- String
节点在站点中表示的页面的 URL。
- title
- String
节点的标签,通常由导航控件显示。
例外
示例
下面的代码示例演示如何使用 SiteMapNode 构造函数创建类的新实例 SiteMapNode 。 该节点使用 access 数据库行中的值初始化Microsoft。
此代码示例是〈c0〉方法的一个较大示例的一部分。
OleDbCommand^ rootNodeCommand = gcnew OleDbCommand
("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid IS NULL", accessConnection);
OleDbDataReader^ rootNodeReader = rootNodeCommand->ExecuteReader();
if ( rootNodeReader->HasRows )
{
rootNodeReader->Read();
rootNodeId = rootNodeReader->GetInt32( 0 );
// Create a SiteMapNode that references the current StaticSiteMapProvider.
rootNode = gcnew SiteMapNode(this, rootNodeId.ToString(),
rootNodeReader->GetString( 1 ),rootNodeReader->GetString( 2 ));
}
else
return nullptr;
rootNodeReader->Close();
OleDbCommand rootNodeCommand =
new OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid IS NULL",
accessConnection);
OleDbDataReader rootNodeReader = rootNodeCommand.ExecuteReader();
if(rootNodeReader.HasRows) {
rootNodeReader.Read();
rootNodeId = rootNodeReader.GetInt32(0);
// Create a SiteMapNode that references the current StaticSiteMapProvider.
rootNode = new SiteMapNode(this,
rootNodeId.ToString(),
rootNodeReader.GetString(1),
rootNodeReader.GetString(2));
}
else
{
return null;
}
rootNodeReader.Close();
Dim rootNodeCommand As New OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid IS NULL", accessConnection)
Dim rootNodeReader As OleDbDataReader = rootNodeCommand.ExecuteReader()
If rootNodeReader.HasRows Then
rootNodeReader.Read()
rootNodeId = rootNodeReader.GetInt32(0)
' Create a SiteMapNode that references the current StaticSiteMapProvider.
aRootNode = New SiteMapNode(Me, rootNodeId.ToString(), rootNodeReader.GetString(1), rootNodeReader.GetString(2))
Else
Return Nothing
End If
rootNodeReader.Close()
注解
该 XmlSiteMapProvider 类是 ASP.NET 的默认 SiteMapProvider 提供程序实现, SiteMapNode.Url 如果为节点提供属性作为查找键(如果未提供 URL,则为节点生成跟踪标识符)。 因此, SiteMapNode 提供 URL 且由 XmlSiteMapProvider 提供程序范围内必须具有唯一 URL 的任何对象。
title如果未提供,则调用Title属性将返回String.Empty字段。
适用于
SiteMapNode(SiteMapProvider, String, String, String, String)
使用指定的 URL 初始化类的新实例 SiteMapNode 、用于 key 标识节点所表示的页面、标题和说明以及管理节点的站点地图提供程序。
public:
SiteMapNode(System::Web::SiteMapProvider ^ provider, System::String ^ key, System::String ^ url, System::String ^ title, System::String ^ description);
public SiteMapNode(System.Web.SiteMapProvider provider, string key, string url, string title, string description);
new System.Web.SiteMapNode : System.Web.SiteMapProvider * string * string * string * string -> System.Web.SiteMapNode
Public Sub New (provider As SiteMapProvider, key As String, url As String, title As String, description As String)
参数
- provider
- SiteMapProvider
与 SiteMapProvider 节点关联的节点。
- key
- String
提供程序特定的查找键。
- url
- String
节点在站点中表示的页面的 URL。
- title
- String
节点的标签,通常由导航控件显示。
- description
- String
节点所表示的页面的说明。
例外
示例
下面的代码示例演示如何使用 SiteMapNode 构造函数通过分析简单文本文件中的数据在内存中生成站点地图来创建 SiteMapNode 对象。
此代码示例是为抽象 SiteMapProvider 类提供的大型示例的一部分。
protected virtual void LoadSiteMapFromStore()
{
string pathToOpen;
lock (this)
{
// If a root node exists, LoadSiteMapFromStore has already
// been called, and the method can return.
if (rootNode != null)
{
return;
}
else
{
pathToOpen = HttpContext.Current.Server.MapPath("~" + "\\" + sourceFilename);
if (File.Exists(pathToOpen))
{
// Open the file to read from.
using (StreamReader sr = File.OpenText(pathToOpen))
{
// Clear the state of the collections and rootNode
rootNode = null;
siteMapNodes.Clear();
childParentRelationship.Clear();
// Parse the file and build the site map
string s = "";
string[] nodeValues = null;
SiteMapNode temp = null;
while ((s = sr.ReadLine()) != null)
{
// Build the various SiteMapNode objects and add
// them to the ArrayList collections. The format used
// is: URL,TITLE,DESCRIPTION,PARENTURL
nodeValues = s.Split(',');
temp = new SiteMapNode(this,
HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[0],
HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[0],
nodeValues[1],
nodeValues[2]);
// Is this a root node yet?
if (null == rootNode &&
string.IsNullOrEmpty(nodeValues[3]))
{
rootNode = temp;
}
// If not the root node, add the node to the various collections.
else
{
siteMapNodes.Add(new DictionaryEntry(temp.Url, temp));
// The parent node has already been added to the collection.
SiteMapNode parentNode =
FindSiteMapNode(HttpRuntime.AppDomainAppVirtualPath + "/" + nodeValues[3]);
if (parentNode != null)
{
childParentRelationship.Add(new DictionaryEntry(temp.Url, parentNode));
}
else
{
throw new Exception("Parent node not found for current node.");
}
}
}
}
}
else
{
throw new Exception("File not found");
}
}
}
return;
}
Protected Overridable Sub LoadSiteMapFromStore()
Dim pathToOpen As String
SyncLock Me
' If a root node exists, LoadSiteMapFromStore has already
' been called, and the method can return.
If Not (aRootNode Is Nothing) Then
Return
Else
pathToOpen = HttpContext.Current.Server.MapPath("~" & "\\" & sourceFilename)
If File.Exists(pathToOpen) Then
' Open the file to read from.
Dim sr As StreamReader = File.OpenText(pathToOpen)
Try
' Clear the state of the collections and aRootNode
aRootNode = Nothing
siteMapNodes.Clear()
childParentRelationship.Clear()
' Parse the file and build the site map
Dim s As String = ""
Dim nodeValues As String() = Nothing
Dim temp As SiteMapNode = Nothing
Do
s = sr.ReadLine()
If Not s Is Nothing Then
' Build the various SiteMapNode objects and add
' them to the ArrayList collections. The format used
' is: URL,TITLE,DESCRIPTION,PARENTURL
nodeValues = s.Split(","c)
temp = New SiteMapNode(Me, _
HttpRuntime.AppDomainAppVirtualPath & "/" & nodeValues(0), _
HttpRuntime.AppDomainAppVirtualPath & "/" & nodeValues(0), _
nodeValues(1), _
nodeValues(2))
' Is this a root node yet?
If aRootNode Is Nothing AndAlso _
(nodeValues(3) Is Nothing OrElse _
nodeValues(3) = String.Empty) Then
aRootNode = temp
' If not the root node, add the node to the various collections.
Else
siteMapNodes.Add(New DictionaryEntry(temp.Url, temp))
' The parent node has already been added to the collection.
Dim parentNode As SiteMapNode = _
FindSiteMapNode(HttpRuntime.AppDomainAppVirtualPath & "/" & nodeValues(3))
If Not (parentNode Is Nothing) Then
childParentRelationship.Add(New DictionaryEntry(temp.Url, parentNode))
Else
Throw New Exception("Parent node not found for current node.")
End If
End If
End If
Loop Until s Is Nothing
Finally
sr.Close()
End Try
Else
Throw New Exception("File not found")
End If
End If
End SyncLock
Return
End Sub
End Class
注解
该 XmlSiteMapProvider 类是 ASP.NET 的默认 SiteMapProvider 提供程序实现, SiteMapNode.Url 如果为节点提供属性作为查找键(如果未提供 URL,则为节点生成跟踪标识符)。 因此, SiteMapNode 提供 URL 且由 XmlSiteMapProvider 提供程序范围内必须具有唯一 URL 的任何对象。
title如果未提供或description已提供,则调用Title或Description属性将返回字段String.Empty。
另请参阅
适用于
SiteMapNode(SiteMapProvider, String, String, String, String, IList, NameValueCollection, NameValueCollection, String)
使用用于管理节点、URL、标题、说明、角色、其他属性以及用于本地化的显式和隐式资源密钥的指定站点地图提供程序初始化类的新实例 SiteMapNode 。
public:
SiteMapNode(System::Web::SiteMapProvider ^ provider, System::String ^ key, System::String ^ url, System::String ^ title, System::String ^ description, System::Collections::IList ^ roles, System::Collections::Specialized::NameValueCollection ^ attributes, System::Collections::Specialized::NameValueCollection ^ explicitResourceKeys, System::String ^ implicitResourceKey);
public SiteMapNode(System.Web.SiteMapProvider provider, string key, string url, string title, string description, System.Collections.IList roles, System.Collections.Specialized.NameValueCollection attributes, System.Collections.Specialized.NameValueCollection explicitResourceKeys, string implicitResourceKey);
new System.Web.SiteMapNode : System.Web.SiteMapProvider * string * string * string * string * System.Collections.IList * System.Collections.Specialized.NameValueCollection * System.Collections.Specialized.NameValueCollection * string -> System.Web.SiteMapNode
Public Sub New (provider As SiteMapProvider, key As String, url As String, title As String, description As String, roles As IList, attributes As NameValueCollection, explicitResourceKeys As NameValueCollection, implicitResourceKey As String)
参数
- provider
- SiteMapProvider
与 SiteMapProvider 节点关联的节点。
- key
- String
提供程序特定的查找键。
- url
- String
节点在站点中表示的页面的 URL。
- title
- String
节点的标签,通常由导航控件显示。
- description
- String
节点所表示的页面的说明。
- roles
- IList
允许查看由
- attributes
- NameValueCollection
用于初始化 . 的其他属性之SiteMapNode一NameValueCollection。
- explicitResourceKeys
- NameValueCollection
NameValueCollection用于本地化的显式资源密钥。
- implicitResourceKey
- String
用于本地化的隐式资源密钥。
例外
注解
该 XmlSiteMapProvider 类是 ASP.NET 的默认 SiteMapProvider 提供程序实现, SiteMapNode.Url 如果为节点提供属性作为查找键(如果未提供 URL,则为节点生成跟踪标识符)。 因此, SiteMapNode 提供 URL 且由 XmlSiteMapProvider 提供程序范围内必须具有唯一 URL 的任何对象。
NameValueCollection通过属性可以使用Attributes创建的属性SiteMapNode集合,并可以轻松地将其他属性应用于站点地图节点并扩展其功能,而无需派生自定义类来执行此操作。
提供角色IList集合,以提供一组角色,这些角色可在属性返回true时SecurityTrimmingEnabled查看节点。 有关详细信息,请参阅 SecurityTrimmingEnabled。
提供程序 XmlSiteMapProvider 使用属性 SiteMapNode.Url 作为查找键。 因此,由提供程序XmlSiteMapProvider使用的任何 SiteMapNode URL 都必须在提供程序范围内具有唯一 URL。
title如果未提供或description已提供,则调用Title或Description属性将返回字段String.Empty。
若要以编程方式指定用于本地化的资源,请将implicitResourceKey值设置为唯一名称,用于标识节点的本地化资源,或设置为NameValueCollectionexplicitResourceKeys一组name/value对,其中name节点属性或自定义属性用于本地化,并value包含节点属性或自定义属性的本地化值。 然后,可以在相应的 .resx 文件中设置本地化值。 有关如何本地化TitleDescription对象的任何自定义属性SiteMapNode的详细信息,请参阅 How to: Localize Site-Map Data。 有关集合的 explicitResourceKeys 语法要求,请参阅 NameValueCollection。