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 872151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:44:31+00:00 2026-05-15T10:44:31+00:00

Currently I am trying to figure out how I can add dynamic query string

  • 0

Currently I am trying to figure out how I can add dynamic query string parameters to my sitemap navigation menu. For example, the user chooses the source and edition he wants to work with. I have a simple sitemap that creates navigational links but the parameters the user chose need to be passed in the query string. The default map looks like this:

<siteMapNode url="" title=""  description="" >
   <siteMapNode url="~/Image.aspx?location=Our Products" title="Our Products" description="Our Products" />
   <siteMapNode url="~/Headline.aspx?location=Our Authors" title="Our Authors"  description="Our Authors" />
</siteMapNode>

Now the links will need to have the parameters added dynamically depending on what was chosen by the user. For example:

<siteMapNode url="~/Image.aspx?location=Our Products&Source=12345&Edition=asdfff" title="Our Products"  description="Our Products" />
<siteMapNode url="~/Headline.aspx?location=Our Authors&Source=12345&Edition=asdfff" title="Our Authors"  description="Our Authors" />

Hopefully this is fairly clear. Let me know if anyone needs deeper explanation.

Thanks

  • 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-15T10:44:32+00:00Added an answer on May 15, 2026 at 10:44 am

    Unfortunately, this is not supported by default. But you can implement the SiteMap.SiteMapResolve event in your Global.asax to catch such extended urls, and call SiteMapProvider.FindSiteMapNode with the correct url:

    private void Application_Start(object sender, EventArgs e)
    {
        SiteMap.SiteMapResolve += ResolveCustomNodes;
    }
    
    private SiteMapNode ResolveCustomNodes(object sender, SiteMapResolveEventArgs e)
    {
        // catch ~/Image.aspx and ~/Headline.aspx
        if (e.Context.Request.AppRelativeCurrentExecutionFilePath.Equals(
            "~/Image.aspx", StringComparison.OrdinalIgnoreCase)
          || e.Context.Request.AppRelativeCurrentExecutionFilePath.Equals(
            "~/Headline.aspx", StringComparison.OrdinalIgnoreCase))
        {
            string location = context.Request.QueryString["location"];
            if (location != null) // ignore everything except location=
                return e.Provider.FindSiteMapNode(
                    e.Context.Request.AppRelativeCurrentExecutionFilePath
                    "?location=" + HttpUtility.UrlEncode(location));
        }
        return null; // use default implementation;
    }
    

    No need for custom SiteMapProviders, this works with any provider.

    Now, if you want to be more dynamic, you can do several things, for example (there are may ways):

    Flag all <siteMapNode> tags with partial querystring matching with a special attribute, and load this list by iterating the entire sitemap. The problem with that approach is that this can be very inefficient for some sitemap providers (the file-based provider is an example of a provider that is a good match for such an approach). What you’d do then, is to say something like

    <siteMapNode url="~/Image.aspx?location=Our Products"
                 queryStringField="location"
                 title="Our Products" description="Our Products" />
    

    In code you could find such nodes recursively by starting at the root node, and remembering all nodes with a queryStringField attribute:

    private IEnumerable<SiteMapNode> FindNodesWithQueryString(SiteMapNode node)
    {
        if (node["queryStringField"] != null)
            yield return node;
        foreach (SiteMapNode childNode in node.ChildNodes)
        {
            foreach (SiteMapNode matchingNode in FindNodesWithQueryString(childNode))
            {
                yield return matchingNode;
            }
        }
    }
    

    With this list in hand, and some hand waving, you should be able to do the same trick. Note that you should probably need to cache this list, because the SiteMapResolve event can be called more often than you’d expect. Especially for database-type SiteMapProviders.

    private SiteMapNode ResolveCustomNodes(object sender, SiteMapResolveEventArgs e)
    {
        string path = e.Context.Request.AppRelativeCurrentExecutionFilePath;
        foreach (var candidate in from node in FindNodesWithQueryString(
                                                                  SiteMap.RootNode)
                                  select new {
                                      Url = node.Url,
                                      UrlNoQuery = node.Url.Split('?')[0],
                                      QueryStringField = node["queryStringField"],
                                      Node = node
                                  } into x
                                  where path.Equals(x.UrlNoQuery, 
                                                 StringComparison.OrdinalIgnoreCase)
                                  select x)
        {
            string paramValue = context.Request.QueryString[
                                                        candidate.QueryStringField];
    
            if (paramValue != null)
            {
                string url = candidate.UrlNoQuery + "?" + candidate.QueryStringField
                           + "=" + HttpUtility.UrlEncode(paramValue);
                if (url.Equals(candidate.Url, StringComparison.OrdinalIgnoreCase))
                    return candidate.Node;
            }   
        }
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.