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

Forums / Developing with Sitefinity / How to convert relative URLs to absolute?

How to convert relative URLs to absolute?

3 posts, 0 answered
  1. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    18 Feb 2009
    Link to this post
    Hi all,

    How I can set absolute URL for each link generated by Sitefinity? Now I have relative URL, e.g. into SiteMenu or then I use ICmsPage.DefaultUrl.Url property in my code.

    Thanks,
    Anton.
  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    18 Feb 2009
    Link to this post
    Hi Anton,

    Thank you for contacting us.

    1. You can use a Control Adapter for the controls you need to have absolute Urls.
    You can see an example for the Hyperlink control attached. Place the file CustomHyperlinkAdapter.cs into your site's App_Code folder. Also change this line from your site's App_Browser/BrowserFile.browser file:
    <browser refID="Default">  
        <controlAdapters> 
    ...  
            <adapter controlType="System.Web.UI.WebControls.HyperLink" adapterType="CustomAdapters.CustomHyperlinkAdapter,App_Code" /> 
        </controlAdapters> 

    You can do the same for the Image control too.

    2. For the Site Menu control, you can make the urls absolute if you add the following to the code in  [your site]\Sitefinity\UserControls\Navigation35\SiteMenu.ascx.cs:
    public void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)  
    {  
    ...  
       e.Item.NavigateUrl =  
       UrlPath.ResolveAbsoluteUrl(e.Item.NavigateUrl,  
       HttpContext.Current.Request.Url.Scheme,  
       HttpContext.Current.Request.Url.Port,  
       HttpContext.Current.Request.Url.Host  
           );  
    ...  
    The same can be applied for the controls like SiteTabStrip,SitePanelBar,SiteTreeView.

    Hope this information will help you.

    Kind regards,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    18 Feb 2009
    Link to this post
    Hi Parvan,

    Thanks, it works!

    Best regards,
    Anton.
Register for webinar
3 posts, 0 answered