Issue with PageSiteNode GetURL function when providing Cultu

Posted by Community Admin on 04-Aug-2018 13:46

Issue with PageSiteNode GetURL function when providing CultureInfo parameter

All Replies

Posted by Community Admin on 22-Jan-2013 00:00

Hi. We have a Sitefinity 5.2 site with multiple cultures (en and en-GB) enabled.

I am trying to perform what should be the simple task of retrieving the URL of each language version of the current page. 

The code below doesn't seem to work. 

For instance on the home page currentPageSiteNode.GetUrl(availableCultureInfo, true) always returns ~/home regardless of the provided CultureInfo object. I would expect to see something like:

~/home
~/en-GB/home

My test code is below

PageSiteNode currentPageSiteNode = SiteMapBase.GetActualCurrentNode();
System.Globalization.CultureInfo[] availableCultures = currentPageSiteNode.AvailableLanguages;
 
string Html = String.Empty;
 
foreach(System.Globalization.CultureInfo availableCultureInfo in availableCultures)
 
    Html += RouteHelper.GetAbsoluteUrl(currentPageSiteNode.GetUrl(availableCultureInfo, true)) + "<br />" + Environment.NewLine;
 
 
Response.Write(Html);

Any help or a workaround would be much appreciated.

Thanks.

Posted by Community Admin on 22-Jan-2013 00:00

Hi Chris,

I'm currently using the code below in a multilingual 5.3 site. It's VB.NET, you can translate it to C# here.

Public Function SitefinityGetVirtualURLofPage(PageID As Guid, Culture As System.Globalization.CultureInfo) As String
            Dim ReturnValue As String = Nothing
 
            Try
                Dim UrlLocalizationService As Telerik.Sitefinity.Localization.UrlLocalizationStrategies.UrlLocalizationService = Telerik.Sitefinity.Abstractions.ObjectFactory.Resolve(Of Telerik.Sitefinity.Localization.UrlLocalizationStrategies.UrlLocalizationService)()
 
                If (UrlLocalizationService IsNot Nothing) Then
                    Dim PageManager As Telerik.Sitefinity.Modules.Pages.PageManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager()
                    Dim PageNode As Telerik.Sitefinity.Pages.Model.PageNode = Nothing
 
                    Try
                        PageNode = PageManager.GetPageNode(PageID)
                    Catch ex As Exception
                        ReturnValue = Nothing
                    End Try
 
                    If (PageNode IsNot Nothing) Then
                        ReturnValue = UrlLocalizationService.ResolvePageUrl(PageNode, Culture)
                    End If
                End If
 
            Catch ex As Telerik.Sitefinity.SitefinityExceptions.ItemNotFoundException
                ' Log the error here
 
                ReturnValue = Nothing
            Catch ex As Exception
                ' Log the error here
 
                ReturnValue = Nothing
            End Try
 
            Return ReturnValue
        End Function

I hope it's useful.

Posted by Community Admin on 22-Jan-2013 00:00

Thanks Arno. I appreciate the assistance. I'll give it a try this afternoon and report back.

Posted by Community Admin on 22-Jan-2013 00:00

Hi Chris,

For my projects I use this function:

/// <summary>
        /// Get a page url
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetPageUrl(Guid id)
 
            CultureInfo currentLanguage = Thread.CurrentThread.CurrentUICulture;
            UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
            var pm = PageManager.GetManager();
            try
                return s.ResolvePageUrl(pm.GetPageNode(id), currentLanguage);
             catch (ItemNotFoundException)
 
                return string.Empty;
            
        

Regards,
Daniel

Posted by Community Admin on 22-Jan-2013 00:00

Arno - Your solution works brilliantly for me thank you for posting!

Posted by Community Admin on 22-Jan-2013 00:00

Thank you Daniel - I'll give your code a try as well. I really appreciate your input.

This thread is closed