SiteMapNode.Url Właściwość

Definicja

Pobiera lub ustawia adres URL strony reprezentowanej przez SiteMapNode obiekt.

C#
public virtual string Url { get; set; }

Wartość właściwości

Adres URL strony reprezentowanej przez węzeł. Wartość domyślna to Empty.

Wyjątki

Węzeł jest tylko do odczytu.

Przykłady

W poniższym przykładzie kodu pokazano, jak ustawić Url właściwość SiteMapNode obiektu. Węzeł AccessSiteMapProvider główny przechowuje jako wiersz, który nie parentnodeid jest zdefiniowany. Wiersz jest zwracany przy użyciu OleDbDataReader obiektu, a SiteMapNode właściwości są ustawiane na podstawie wartości w czytniku danych.

Ten przykład kodu jest częścią większego przykładu udostępnionego SiteMapProvider dla klasy .

C#
// 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;
    }
}

Uwagi

Klasa XmlSiteMapProvider , która jest domyślną implementacją dostawcy mapy witryny dla ASP.NET, używa SiteMapNode.Url właściwości jako klucza wyszukiwania. W związku z tym każdy SiteMapNode obiekt używany przez XmlSiteMapProvider klasę musi mieć unikatowy adres URL w zakresie dostawcy.

Znaki wiodące i końcowe odstępów są ignorowane.

Dotyczy

Produkt Wersje
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Zobacz też