Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 416551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:29:30+00:00 2026-05-12T18:29:30+00:00

We have a website that uses a bog-standard default sitemap with security trimming as

  • 0

We have a website that uses a bog-standard default sitemap with security trimming as follows:

<siteMap defaultProvider="default" enabled="true">
  <providers>
    <add siteMapFile="~/Web.sitemap" securityTrimmingEnabled="true" name="default" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </providers>
</siteMap>

All very well, but a request has come in to change the Title of one node based on some back-end criteria. Sounds like a simple thing, but apparently not.

Attempt 1 – Handling the SiteMapResolve event. It doesn’t appear to matter where this event is handled, I have shown it in Global.asax merely because that was one of the places I tried it and it worked.

Public Class Global_asax
    Inherits System.Web.HttpApplication

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        AddHandler SiteMap.SiteMapResolve, AddressOf SiteMapResolve
    End Sub

    Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs)
        RemoveHandler SiteMap.SiteMapResolve, AddressOf SiteMapResolve
    End Sub

    Private Shared Function SiteMapResolve(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode

        Dim node As SiteMapNode = SiteMap.CurrentNode
        If IsThisTheNodeToChange(node) Then
            node = node.Clone()
            node.Title = GetNodeTitle()
        End If
        Return node

    End Function

End Class

This worked fine when the relevant page was navigated to, but unfortunately part of the site navigation involves a combo box that is data-bound to the site map like this:

<asp:SiteMapDataSource ID="siteMapDataSource" runat="Server" ShowStartingNode="false" StartFromCurrentNode="false" StartingNodeOffset="1" />
<asp:DropDownList ID="pageMenu" runat="Server" AutoPostBack="True" DataSourceID="siteMapDataSource" DataTextField="Title" DataValueField="Url" />

When this menu is rendered, the SiteMapResolve event does not fire for any of the contents because the current node is the page on which the menu is defined. As a result, the menu shows the nonsense placeholder title from the physical sitemap file rather than the correct title.

Attempt 2 – Writing my own sitemap provider. I didn’t want to duplicate all the default behaviour, so I tried deriving from the default provider as follows.

Public Class DynamicXmlSiteMapProvider
    Inherits XmlSiteMapProvider

    Private _dataFixedUp As Boolean = False

    Public Overrides Function GetChildNodes(ByVal node As SiteMapNode) As SiteMapNodeCollection

        Dim result As SiteMapNodeCollection = MyBase.GetChildNodes(node)
        If Not _dataFixedUp Then
            For Each childNode As SiteMapNode In result
                FixUpNode(childNode)
            Next
        End If
        Return result

    End Function

    Private Sub FixUpNode(ByVal node As SiteMapNode)

        If IsThisTheNodeToChange(node) Then
            node.ReadOnly = False
            node.Title = GetNodeTitle()
            node.ReadOnly = True
            _dataFixedUp = True
        End If

    End Sub

End Class

This doesn’t work because GetChildNodes doesn’t appear to be called very often when navigating around the site.

Attempt 3 – Try to fix the data immediately after it’s loaded into memory, rather than when it’s accessed.

Public Class DynamicXmlSiteMapProvider
    Inherits XmlSiteMapProvider

    Private _dataFixInProgress As Boolean = False
    Private _dataFixDone As Boolean = False

    Public Overrides Function BuildSiteMap() As SiteMapNode

        Dim result As SiteMapNode = MyBase.BuildSiteMap()
        If Not _dataFixInProgress AndAlso Not _dataFixDone Then
            _dataFixInProgress = True
            For Each childNode As SiteMapNode In result.GetAllNodes()
                FixUpNode(childNode)
            Next
            _dataFixInProgress = False
            _dataFixDone = True
        End If
        Return result

    End Function

    Private Sub FixUpNode(ByVal node As SiteMapNode)

        If IsThisTheNodeToChange(node) Then
            node.ReadOnly = False
            node.Title = GetNodeTitle()
            node.ReadOnly = True
        End If

    End Sub

End Class

This appears to work. However, I’m worried about the call to GetAllNodes in the BuildSiteMap method. It just seems wrong to me to recursively pull all data into memory just to fix up one value. Also, I have no control over when BuildSiteMap is called. I would prefer something more like Attempt 1, that is called on demand when the node data is first required.

Attempt 4 (NEW) – Like Attempt 2, but overriding all virtual members that are to do with reading data (CurrentNode, FindSiteMapNode, FindSiteMapNodeFromKey, GetChildNodes, GetCurrentNodeAndHintAncestorNodes, GetCurrentNodeAndHintNeighborhoodNodes, GetParentNode, GetParentNodeRelativeToCurrentNodeAndHintDownFromParent, GetParentNodeRelativeToNodeAndHintDownFromParent, HintAncestorNodes, HintNeighborhoodNodes), to try to intercept the reading of the dynamic node somewhere.

This did not work. I put debug statements in all the overridden members, and it seems that none of them at all are called when data binding to the dropdown list. The only explanation I can think of is that the nodes are all read into memory in one go during the BuildSiteMap call, so that the SiteMapNode is not hitting the provider class when enumerating child nodes.

Does anyone have any better suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:29:30+00:00Added an answer on May 12, 2026 at 6:29 pm

    In our Custom SiteMapProvider we override the BuildSiteMap Method and construct the SiteMapNodes manually. To change and/or add custom properties we add custom attributes to the SiteMapNodes by create a NameValueCollection and add pass this to the SiteMapNode Constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that uses the old fb:comments: <fb:comments xid=2 title=My website notify=true
We have a website that uses #include file command to roll info into some
I have a website that uses JSP as its view technology (and Spring MVC
I have a website that uses basic ASP.Net forms authentication. In the web.config file
I have a website that uses the facebook, twitter, delicious share links. They contain
I have a website that uses flash. I would like to convert the website
I have a website that uses the AjaxControlToolkit. I'm making some parallel iPhone-friendly pages
I have a website that uses OpenID to sign in users. The library I'm
We have developed a website that uses MVC, C#, and jQuery. In one of
I have an existing website that uses the same code base, but is deployed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.