node工程默认url_SiteMapNode.Url

获取或设置 SiteMapNode 对象所代表的页的 URL。Gets or sets the URL of the page that the SiteMapNode object represents.

public:

virtual property System::String ^ Url { System::String ^ get(); void set(System::String ^ value); };

public virtual string Url { get; set; }

member this.Url : string with get, set

Public Overridable Property Url As String

属性值

该节点所代表的页的 URL。The URL of the page that the node represents. 默认值为 Empty。The default is Empty.

例外

该节点是只读的。The node is read-only.

示例

下面的代码示例演示如何设置对象的 Url 属性 SiteMapNode 。The following code example demonstrates how to set the Url property of a SiteMapNode object. 将 AccessSiteMapProvider 其根节点存储为未定义的行 parentnodeid 。The AccessSiteMapProvider stores its root node as a row that has no parentnodeid defined. The row is returned using an OleDbDataReader object, and SiteMapNode properties are set from the values in the data reader.

此代码示例是为类提供的更大示例的一部分 SiteMapProvider 。This code example is part of a larger example provided for the SiteMapProvider class.

// Build an in-memory representation from persistent

// storage, and return the root node of the site map.

virtual SiteMapNode ^ BuildSiteMap() override

{

// Since the SiteMap class is static, make sure that it is

// not modified while the site map is built.

System::Threading::Monitor::Enter( this );

try

{

// If there is no initialization, this method is being

// called out of order.

if ( !IsInitialized )

{

throw gcnew Exception( "BuildSiteMap called incorrectly." );

}

// If there is no root node, then there is no site map.

if ( nullptr == rootNode )

{

// Start with a clean slate

Clear();

// Select the root node of the site map from Microsoft Access.

int rootNodeId = -1;

if ( accessConnection->State == ConnectionState::Closed )

accessConnection->Open();

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();

// Select the child nodes of the root node.

OleDbCommand^ childNodesCommand = gcnew OleDbCommand

("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid = ?", accessConnection);

OleDbParameter^ rootParam = gcnew OleDbParameter( "parentid", OleDbType::Integer);

rootParam->Value = rootNodeId;

childNodesCommand->Parameters->Add( rootParam );

OleDbDataReader^ childNodesReader = childNodesCommand->ExecuteReader();

if ( childNodesReader->HasRows )

{

SiteMapNode ^ childNode = nullptr;

while ( childNodesReader->Read() )

{

childNode = gcnew SiteMapNode( this,

System::Convert::ToString(childNodesReader->GetInt32( 0 )),

childNodesReader->GetString( 1 ),

childNodesReader->GetString( 2 )

);

// Use the SiteMapNode AddNode method to add

// the SiteMapNode to the ChildNodes collection.

AddNode( childNode, rootNode );

}

}

childNodesReader->Close();

accessConnection->Close();

}

return rootNode;

}

finally

{

System::Threading::Monitor::Exit( this );

}

}// Build an in-memory representation from persistent

// storage, and return the root node of the site map.

public override SiteMapNode BuildSiteMap() {

// Since the SiteMap class is static, make sure that it is

// not modified while the site map is built.

lock(this) {

// If there is no initialization, this method is being

// called out of order.

if (! IsInitialized) {

throw new Exception("BuildSiteMap called incorrectly.");

}

// If there is no root node, then there is no site map.

if (null == rootNode) {

// Start with a clean slate

Clear();

// Select the root node of the site map from Microsoft Access.

int rootNodeId = -1;

if (accessConnection.State == ConnectionState.Closed)

accessConnection.Open();

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();

// Select the child nodes of the root node.

OleDbCommand childNodesCommand =

new OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid = ?",

accessConnection);

OleDbParameter rootParam = new OleDbParameter("parentid", OleDbType.Integer);

rootParam.Value = rootNodeId;

childNodesCommand.Parameters.Add(rootParam);

OleDbDataReader childNodesReader = childNodesCommand.ExecuteReader();

if (childNodesReader.HasRows) {

SiteMapNode childNode = null;

while(childNodesReader.Read()) {

childNode = new SiteMapNode(this,

childNodesReader.GetInt32(0).ToString(),

childNodesReader.GetString(1),

childNodesReader.GetString(2));

// Use the SiteMapNode AddNode method to add

// the SiteMapNode to the ChildNodes collection.

AddNode(childNode, rootNode);

}

}

childNodesReader.Close();

accessConnection.Close();

}

return rootNode;

}

}' Build an in-memory representation from persistent

' storage, and return the root node of the site map.

Public Overrides Function BuildSiteMap() As SiteMapNode

' Since the SiteMap class is static, make sure that it is

' not modified while the site map is built.

SyncLock Me

' If there is no initialization, this method is being

' called out of order.

If Not IsInitialized Then

Throw New Exception("BuildSiteMap called incorrectly.")

End If

' If there is no root node, then there is no site map.

If aRootNode Is Nothing Then

' Start with a clean slate

Clear()

' Select the root node of the site map from Microsoft Access.

Dim rootNodeId As Integer = -1

If accessConnection.State = ConnectionState.Closed Then

accessConnection.Open()

End If

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

' Select the child nodes of the root node.

Dim childNodesCommand As New OleDbCommand("SELECT nodeid, url, name FROM SiteMap WHERE parentnodeid = ?", accessConnection)

Dim rootParam As New OleDbParameter("parentid", OleDbType.Integer)

rootParam.Value = rootNodeId

childNodesCommand.Parameters.Add(rootParam)

Dim childNodesReader As OleDbDataReader = childNodesCommand.ExecuteReader()

If childNodesReader.HasRows Then

Dim childNode As SiteMapNode = Nothing

While childNodesReader.Read()

childNode = New SiteMapNode(Me, _

childNodesReader.GetInt32(0).ToString(), _

childNodesReader.GetString(1), _

childNodesReader.GetString(2))

' Use the SiteMapNode AddNode method to add

' the SiteMapNode to the ChildNodes collection.

AddNode(childNode, aRootNode)

End While

End If

childNodesReader.Close()

accessConnection.Close()

End If

Return aRootNode

End SyncLock

End Function 'BuildSiteMap

注解

XmlSiteMapProvider类是 ASP.NET 的默认站点地图提供程序实现,它使用 SiteMapNode.Url 属性作为查找键。The XmlSiteMapProvider class, which is the default site map provider implementation for ASP.NET, uses the SiteMapNode.Url property as a lookup key. 因此, SiteMapNode 类使用的任何对象都必须在 XmlSiteMapProvider 提供程序的作用域内具有唯一的 URL。Therefore, any SiteMapNode object that is used by the XmlSiteMapProvider class must have a unique URL within the scope of the provider.

将忽略前导空格和尾随空白字符。Leading and trailing white-space characters are ignored.

适用于

另请参阅

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值