+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Resolving relative urls

Resolving relative urls

4 posts, 0 answered
  1. Olivier
    Olivier avatar
    57 posts
    Registered:
    09 Jul 2010
    15 Oct 2010
    Link to this post
    Hi,

    I created a new sitemenu control (load on demand), and I need to resolve relative urls (starting with ~) to absolute urls.

    But I cant get it as well as you did in your menu, is it possible to know how you did it ? If there's a function or something?

    I have problems with ports in urls, which have to be specified or not...

    Thank you,

    Olivier
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Oct 2010
    Link to this post
    Hi Olivier,

    We use the SiteMapData source and resolve the url depending on the current host from the HttpContext. Inside ItemDataBound you have access to the data item object and RadMenuItem, so you can easily set the NavigateUrl of the item.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Oct 2010
    Link to this post
    Hello Olivier,

    In the sample I have sent I am using VirtualPathUtility.ToAbsolute() method which resolves an application relative path to absolute path starting from the site node. This should be sufficient to resolve the links.

    public RadMenuItemData[] LoadData(RadMenuItemData item, object context)
        {
            List<RadMenuItemData> items = new List<RadMenuItemData>();
            var siteMapNode = SiteMap.Provider.FindSiteMapNodeFromKey(item.Value);
            var nodes = SiteMap.Provider.GetChildNodes(siteMapNode);
     
            foreach (SiteMapNode node in nodes)
            {
                RadMenuItemData newItem = new RadMenuItemData();
                CmsSiteMapNode cmsNode = (CmsSiteMapNode)node;
     
                newItem.Text = cmsNode.CmsPage.MenuName;
                newItem.Value = cmsNode.Key;
                if (cmsNode.CmsPage.PageType == Telerik.Cms.CmsPageType.Group)
                    newItem.NavigateUrl = "";
                else newItem.NavigateUrl = VirtualPathUtility.ToAbsolute(node.Url);
                if (node.ChildNodes.Count>0)
                    newItem.ExpandMode = MenuItemExpandMode.WebService;
                items.Add(newItem);
            }
            return items.ToArray();
        }

    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Olivier
    Olivier avatar
    57 posts
    Registered:
    09 Jul 2010
    15 Oct 2010
    Link to this post
    Thanks for your answer !
Register for webinar
4 posts, 0 answered