Assembly : System.Web (dans system.web.dll)
SyntaxePublic Class SiteMapNode Implements ICloneable, IHierarchyData, INavigateUIData
Dim instance As SiteMapNode
public class SiteMapNode : ICloneable, IHierarchyData, INavigateUIData
public ref class SiteMapNode : ICloneable, IHierarchyData, INavigateUIData
public class SiteMapNode implements ICloneable, IHierarchyData, INavigateUIData
public class SiteMapNode implements ICloneable, IHierarchyData, INavigateUIData
NotesUn objet SiteMapNode représente une page de site Web au sein d'une structure de plan de site. Les objets SiteMapNode sont chargés par la classe statique SiteMap au moment de l'exécution, à l'aide d'un ou plusieurs fournisseurs de plan de site afin de charger des données de plan de site à partir d'un stockage persistant en mémoire. Les objets SiteMapNode sont encapsulés par la classe SiteMapNodeItem pour être utilisés par des contrôles de serveur Web, tels que le contrôle SiteMapPath.
La classe SiteMapNode comprend plusieurs propriétés utilisées pour décrire une page unique au sein d'un site Web, notamment les propriétés de description de page, telles que Url, Title et Description. Tandis que la propriété Url est utilisée par la classe XmlSiteMapProvider, qui constitue le fournisseur de plan de site ASP.NET par défaut, à l'instar d'une clé de recherche dans les collections internes que le fournisseur utilise pour suivre des n?uds, la classe SiteMapNode prend en charge une propriété Key de base, que des fournisseurs de plan de site peuvent utiliser pour suivre des n?uds. En outre, la propriété Url est utilisée par les contrôles de navigation pour générer le rendu des liens hypertexte vers des pages au sein d'une structure de navigation. La propriété Title est le nom convivial du SiteMapNode. Il correspond souvent au titre HTML d'un formulaire Web. Il est utilisé par les contrôles de navigation pour restituer des étiquettes simples. Enfin, une collection NameValueCollection d'attributs Attributes supplémentaires est à la disposition des fournisseurs de plan de site qui utilisent des objets SiteMapNode, mais requièrent des propriétés supplémentaires indisponibles dans la classe de base SiteMapNode.
ExempleCette section comprend deux exemples de code. Le premier exemple de code montre comment créer une nouvelle collection de n?uds du plan de site, et comment lui ajouter des éléments. Le deuxième exemple de code montre comment charger des données de plan de site à partir d'un fichier texte.
L'exemple de code suivant montre comment utiliser le constructeur SiteMapNodeCollection pour créer une nouvelle collection SiteMapNodeCollection, puis comment lui ajouter des éléments avec la méthode Add.
' 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
// 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; }
L'exemple de code suivant montre comment le SimpleTextSiteMapProvider analyse un fichier texte qui renferme des données de plan de site dans des chaînes délimitées par des virgules. Un nouvel objet SiteMapNode est ajouté aux collections de suivi interne de la classe pour chaque ligne lue dans le fichier.
Ce code fait partie d'un plus grand exemple fourni pour la classe SiteMapProvider.
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 'LoadSiteMapFromStore End Class 'SimpleTextSiteMapProvider
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 && (null == nodeValues[3] || nodeValues[3] == String.Empty)) { 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; }
Sécurité .NET Framework- AspNetHostingPermission pour opérer dans un environnement hébergé. Valeur de demande : LinkDemand ; valeur d'autorisation : Minimal.
- AspNetHostingPermission pour opérer dans un environnement hébergé. Valeur de demande : InheritanceDemand ; valeur d'autorisation : Minimal.
Sécurité des threads
Plates-formesWindows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ