SiteMapNode.Url Property
Assembly: System.Web (in system.web.dll)
/** @property */ public String get_Url () /** @property */ public void set_Url (String value)
public function get Url () : String public function set Url (value : String)
Property Value
The URL of the page that the node represents. The default is String.Empty.The XmlSiteMapProvider class, which is the default site map provider implementation for ASP.NET, uses the SiteMapNode.Url property as a lookup key. Therefore, any SiteMapNode object that is used by the XmlSiteMapProvider class must have a unique URL within the scope of the provider.
| Topic | Location |
|---|---|
| How to: Programmatically Modify Site-Map Nodes in Memory | Building ASP .NET Web Applications |
| How to: Programmatically Modify Site-Map Nodes in Memory | Building ASP .NET Web Applications |
The following code example demonstrates how to set the Url property of a SiteMapNode object. 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.
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 SiteMapNode BuildSiteMap() throws Exception
{
// Since the SiteMap class is static, make sure that it is
// not modified while the site map is built.
synchronized (this)
{
// If there is no initialization, this method is being
// called out of order.
if (!get_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.get_State().Equals(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.get_HasRows())
{
rootNodeReader.Read();
rootNodeId = rootNodeReader.GetInt32(0);
// Create a SiteMapNode that references the current
// StaticSiteMapProvider.
rootNode = new SiteMapNode(this,
((Int32)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.set_Value((Int32)rootNodeId);
childNodesCommand.get_Parameters().Add(rootParam);
OleDbDataReader childNodesReader = childNodesCommand.
ExecuteReader();
if (childNodesReader.get_HasRows())
{
SiteMapNode childNode = null;
while (childNodesReader.Read())
{
childNode = new SiteMapNode(this,
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;
}
} //BuildSiteMap
protected SiteMapNode GetRootNodeCore()
{
return null;
} //GetRootNodeCore
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.