Get URL - different language

Posted by Community Admin on 03-Aug-2018 15:20

Get URL - different language

All Replies

Posted by Community Admin on 24-Nov-2010 00:00

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 ?

Posted by Community Admin on 24-Nov-2010 00:00

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

This thread is closed