Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 4 of 4

Thread: Issue with asp:Menu and external links

  1. #1
    tigreye007 is offline Junior Member
    Join Date
    Nov 2008
    Posts
    27

    Default Issue with asp:Menu and external links

    In the new ML 9.0.1.2, I'm trying to add a sitemap node to page.menu.xml.config that will link to an external site as follows:

    HTML Code:
    <siteMapNode title="Go To Other Site" url="http://www.othersite.com" />
    This causes an error in SiteMapProviderFactory.cs: "'http://www.othersite.com' is not a valid virtual path". How can I add an external link to the asp:Menu?

  2. #2
    tigreye007 is offline Junior Member
    Join Date
    Nov 2008
    Posts
    27

    Default

    I guess I answered my own question. I found a workaround here:
    http://www.joeaudette.com/using-an-e...-provider.aspx

    Info: If you add the node (using the AddNode() method), then later change the node.Url to the "http://www.othersite.com", the system won't complain. The reason I am using Guid.NewGuid as the initial page name is because the sitemap provider requires unique URLs (so if you have multiple external links, hard-coding a valid virtual directory is not an option).

    Implemented in ASPDNSFSiteMapProvider.cs:


    #region BuildSiteMapTree
    /// <summary>
    /// Core function to build the sitemap tree together with it's hierarchy
    /// </summary>
    /// <param name="nav">The XPathNavigator object</param>
    /// <param name="parent">The parent node</param>
    private void BuildSiteMapTree(XPathNavigator nav, SiteMapNode parent)
    {
    XPathNodeIterator enumerator = nav.Select("siteMapNode");
    while (enumerator.MoveNext())
    {
    XPathNavigator current = enumerator.Current;

    if (IsEntityNode(current))
    {
    SiteMapNode entityNode = NewSiteMapNode(current);
    AddNode(entityNode, parent);
    FixExternalLink(ref entityNode, current);
    LoadEntity(ExtractType(current), entityNode);
    }
    else
    {
    SiteMapNode node = NewSiteMapNode(current);
    AddNode(node, parent);
    FixExternalLink(ref node, current);

    BuildSiteMapTree(current, node);
    }
    }
    }
    #endregion

    #region NewSiteMapNode
    /// <summary>
    /// Returns a new instance of SiteMapNode using the title and url attributes
    /// </summary>
    /// <param name="nav">The XPathNavigator object</param>
    /// <returns></returns>
    private SiteMapNode NewSiteMapNode(XPathNavigator nav)
    {
    string title = ExtractTitle(nav);
    string url = nav.GetAttribute("url", string.Empty);

    SiteMapNode node = new SiteMapNode(this, NewKey(), url, title);

    if (url.StartsWith("http"))
    {
    node.Url = Guid.NewGuid().ToString() + ".aspx";
    }

    return node;

    }

    private void FixExternalLink(ref SiteMapNode node, XPathNavigator nav)
    {
    string url = nav.GetAttribute("url", string.Empty);
    node.Url = url;
    }

    #endregion

  3. #3
    freeborough is offline Junior Member
    Join Date
    Jun 2008
    Posts
    9

    Default Thanks

    Thanks Tigreye007, I just came across this problem when upgrading a site to 9.1 and this fixed it perfectly. I wonder if your changes could be pushed into the core product to save others the time they'll no doubt spend on it before finding this thread.

    Thanks,

    - Andy.

  4. #4
    digitalranch is offline Junior Member
    Join Date
    Aug 2011
    Posts
    2

    Default Works great!

    This solution works great. I'm not sure why we are taking two steps back with aspnetMenu but this helps. Now if I can just resolve the issue with setting the target for the menu item...