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

Forums / General Discussions / Get URL - different language

Get URL - different language

2 posts, 1 answered
  1. JV
    JV avatar
    74 posts
    Registered:
    15 Jun 2012
    24 Nov 2010
    Link to this post
    I have one custom language selector control and i'm trying to obtain the URL of my current page in all avaiable languages (in my site i have configurated the default language PT and other avaialbe is EN):
    ........................
      SiteMapNode currentNode = SiteMapBase.GetCurrentProvider().CurrentNode;
      pagen = pm.GetPageNode( new Guid(currentNode.Key));
    ..................
     void LanguagesRepeater_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
            {
                CultureInfo ci = (System.Globalization.CultureInfo)e.Item.DataItem;
              
                if (ci != null)
                {
                   ..............................................
                
                    if (pagen != null)
                    {
                       if (pagen.AvailableLanguages.Contains(ci.Name))
                           lk.HRef = pagen.GetUrl(ci);
                        else
                           lk.HRef = homePageNode.GetUrl(ci);
                    }
                    else
                    {

                        lk.HRef = homePageNode.GetUrl(ci);
                    }
                }
            }


    The problem is that  pagen.GetUrl(ci) returns allways the URL to the default language in pages that i have the english version ( never returns url of the type ~/en/home   ).

    What am i doing wrong ?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Nov 2010
    Link to this post
    Hi JV,

    You have to resolve the url depending on the culture

    string url = null;
    UrlLocalizationService service = new UrlLocalizationService();
    url = service.ResolvePageUrl(node, culture);


    Greetings,
    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
    Answered
2 posts, 1 answered