PageNode.GetFullUrl() returns invalid URL - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

PageNode.GetFullUrl() returns invalid URL

  • PageNode.GetFullUrl() returns invalid URL
  • I'm writing a master page. For some reason, the contents of the three strings at the end are invalid: if the URL in my browser is "site.com/home", then the variables contain "~/home". If I adjust the URL in my browser to "site.com/fr/home", then the variables contain "~/fr/home". It seems that regardless of the arguments I try passing to GetFullUrl, it parrots back the path with the application root represented as "~".

    I have tried performing Google and forum searches, but no-one else seems to have this issue. English and French are enabled as public content languages in the Administration area and Multilingual URLs is set to Directories. I'm using Sitefinity 4.1.1501.0.

    using System;
    using System.Globalization;
    using System.Threading;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Modules.Pages.Configuration;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Web;
     
    namespace SitefinityWebApp
        public partial class CLF2 : System.Web.UI.MasterPage
        
            private CultureInfo fr = CultureInfo.GetCultureInfo("fr"); // French
            private CultureInfo en = CultureInfo.GetCultureInfo("en"); // English
     
            protected void Page_Load(object sender, EventArgs e)
            
                // Page manager; for getting info about pages
                PageManager manager = PageManager.GetManager();
                 
                // For getting site configuration information
                PagesConfig config = Config.Get<PagesConfig>();
                 
                // Current node; for where we are in the site map
                PageSiteNode currentNode = SiteMapBase.GetActualCurrentNode();
                 
                // Home node; CMS information about the home page
                PageNode homeNode = manager.GetPageNode(config.HomePageId);
                 
                // Page node; CMS information about this page
                PageNode thisNode = manager.GetPageNode(currentNode.Id);
                 
                // Homepage URL
                String enHomeUrl = homeNode.GetFullUrl(en, false);
               String frHomeUrl = homeNode.GetFullUrl(fr, false);
                 
                // URL for alternate language page
                String frUrl = homeNode.GetFullUrl(
                   Thread.CurrentThread.CurrentCulture.Equals(fr) ? fr : en, false);
            
        

    Any help would be greatly appreciated, thank you!
  • Hello Stephen,

    The method that you need yo use in order to obtain the absolute url is this one: RouteHelper.GetAbsoluteUrl
    Please modifiy the last line of your code as follows and check whether it works.

    String frUrl = RouteHelper.GetAbsoluteUrl(Thread.CurrentThread.CurrentCulture.Equals(fr) ? frHomeUrl : enHomeUrl);

    Please let me know if you have any problems.

    All the best,
    Lilia Messechkova
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • RouteHelper.GetAbsoluteUrl() did turn the URL into something usable. But as 

                String enHomeUrl = homeNode.GetFullUrl(en, false);
               String frHomeUrl = homeNode.GetFullUrl(fr, false);

    are identical strings, the result of GetAbsoluteURL() is always the same.

    It is progress, but something else is needed. 

    Does PageNode's PageExtesnsions.GetAbsoluteURL(CulturalInfo, boolean) ignore its parameters? Am I using this method incorrectly?

  • Hello Stephen,

    I found a problem in the GetFullUrl method. It uses the culture of the current thread  and the not the one specified as parameter at some places. Here is a work around:

                Thread.CurrentThread.CurrentCulture = en;
                Thread.CurrentThread.CurrentUICulture = en;
                String enHomeUrl = homeNode.GetFullUrl(CultureInfo.CurrentUICulture, true);

                Thread.CurrentThread.CurrentCulture = fr;
                Thread.CurrentThread.CurrentUICulture = fr;
                String frHomeUrl = homeNode.GetFullUrl(CultureInfo.CurrentUICulture, true);

    You need to change the culture of the current thread before obtaining the full url in the culture that you want. In that case enHomeUrl and frHomeUrl should be different and correct relative paths. There is one more specific thing with that method, it returns the url in the default culture if the page is not published, so your code will work for published pages only.

    I really hope that this will solve your problem. If you have further issues please let me know.

    Kind regards,
    Lilia Messechkova
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • This workaround... worked. :)

    Hopefully this bug will be resolved soon :)
  • This bug is still there in 5.1 SP2.

    This is a moderately severe bug and also seems like it would be easy to fix. Is there any plans to fix it?
  • This bug is still there in 5.1 SP2.

    This is a moderately severe bug and also seems like it would be easy to fix. Is there any plans to fix it?
  • It still exists (version 5.4 4020)! .....
    And with another bug. If you change the current culture you get back the url in this culture except the page. For example:
    for el I get "~/οι-υπηρεσίες-μας/σχετικές-συμβάσεις-έγγραφα"
    for en I get "~/en/our-services/σχετικές-συμβάσεις-έγγραφα"
    "σχετικές-συμβάσεις-έγγραφα" in English is "relative-documents" so I get a page not found...
  • Hi,

    To get the correct language version of the page use the code below:
    //get the correct node for language
                var node = PageHelper.GetPageNodeForLanguage(pm.GetPageNodes().Where(n => n.Title == "syncEN").SingleOrDefault(), currentLanguage);
      
                Thread.CurrentThread.CurrentUICulture = currentLanguage;
                var urlForPage = node.GetFullUrl();
                urlForPage = s.ResolveUrl(urlForPage, currentLanguage);
      
                return urlForPage;


    Regards,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Hi All,

     I am using Sitefinity 7.0 and still having problems

    Just created Germen (de) version of Website on navigation I get page url as www.mywebsite.com/ge/aboutus although when I try to get it programmatically I am always getting www.mywebiste.com/aboutus. Tried 100 different ways (may be only 30 and spent 4 hours)

      

    protected void Page_Load(object sender, EventArgs e)
            
                var pageNode = SiteMap.RootNode.RootNode;
     
                var site = Telerik.Sitefinity.Services.SystemManager.CurrentContext.CurrentSite;           
                var homePageId = new Guid("E0F18963-472E-627F-855A-FF0000094B1C");// site.HomePageId;
     
                PageManager pageManager = PageManager.GetManager();
                PageData page = pageManager.GetPageDataList().Where(p => p.NavigationNode.Id == homePageId).FirstOrDefault();
                if (page != null)
                               
                    var page12 = pageManager.GetPageDataList().Where(p => p.NavigationNode.IsBackend == false && p.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
                    //var page13 = pageManager.GetPageDataList().Where(p => p.Id == homePageId).SingleOrDefault();
                    //var page14 = pageManager.GetPageDataList().Where(p => p.NavigationNode.PageId == homePageId).SingleOrDefault();
                    var pagecluture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
                    var page15 = pageManager.GetPageDataList().Where(p => p.NavigationNode.Id == homePageId && p.Culture == pagecluture).FirstOrDefault();
                    if (page15 != null)
                    
                        var FullURL15 = page15.NavigationNode.GetFullUrl();
                        var url15 = page15.NavigationNode.GetUrl();
                        var url151 = page15.NavigationNode.GetUrl(pagecluture);
                        var fullurl = UrlPath.ResolveUrl(url15, true, true);
                        var fullurl2 = UrlPath.ResolveUrl(url151, true, true);
                        var fullurl21 = RouteHelper.GetAbsoluteUrl(url151);
                        var NavNode = page15.NavigationNode;
     
                        var pageurlis = GetUrlByPageNodeIdAlternative(homePageId, pagecluture, true);
                        var pageurlis2 = GetUrlByPageNodeIdAlternative(homePageId, pagecluture, false);
                    
     
     
                
            
     
     
    private string GetUrlByPageNodeIdAlternative(Guid pageNodeId, string targetCulture, bool resolveAsAbsolutUrl)
            
                var siteMap = SiteMapBase.GetCurrentProvider();
     
                // Get the siteMapNode
                var siteMapNode = siteMap.FindSiteMapNodeFromKey(pageNodeId.ToString()) as PageSiteNode;
                var culture = System.Globalization.CultureInfo.GetCultureInfo(targetCulture);
                var url = String.Empty;
                if (siteMapNode != null)
                
                    // Get the URL of the siteMapNode
                    url = siteMapNode.GetUrl(culture, false);
                    if (resolveAsAbsolutUrl)
                    
                        // Get the absolute URL of the pageNode
                        url = UrlPath.ResolveUrl(url, true, true);
                    
                
                return url;
            

     

    With regards

     

     

     

  • Hi Stanislav,

     

    I was wondering what letter "s" stands for in your sample

    urlForPage = s.ResolveUrl(urlForPage, currentLanguage);

     

    Thanks

  • Hi,

    The way to resolve the correct language specific Url is below. It uses UrlLocalizationService to resolve the current culture prefix for each url.

    I have provided several approaches to the achieve this.
    var currentLanguage = Thread.CurrentThread.CurrentUICulture;
               var pageUrl = SiteMapBase.GetActualCurrentNode().Id;
      
      
               //CultureInfo currentLanguage = new CultureInfo("en");
               Thread.CurrentThread.CurrentUICulture = currentLanguage;
               PageManager pm = PageManager.GetManager();
               UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
               var pageNode = pm.GetPageNodes().Where(n => n.Id == pageUrl).FirstOrDefault();
      
               // approach 1
               var node = PageHelper.GetPageNodeForLanguage(pageNode, currentLanguage);
               var urlForPage = node.GetFullUrl();
               //the correct url gets returned here.
               urlForPage = s.ResolveUrl(urlForPage, currentLanguage);
      
               //approach2
               var approach3Url = pageNode.GetFullUrl(currentLanguage, false);
      
               //approach3
               var approach4Url = Page.ResolveUrl(approach3Url);
      
               //approach4
      
               var approach5Url = ObjectFactory.Resolve<UrlLocalizationService>().ResolveUrl(approach3Url);
      
               //approach5
               //double resolving url occurs here also
               var approach6Url = ObjectFactory.Resolve<UrlLocalizationService>()
                   .ResolveUrl(PageHelper.GetPageNodeForLanguage(pageNode, currentLanguage)
                   .GetFullUrl(currentLanguage, false), currentLanguage);



    Regards,
    Stanislav Velikov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  • Can you put this in the localization documentation? 

    docs.sitefinity.com/for-developers-localize-pages-and-content