Retrieving page URLs in a multilingual website
Hi,
I'm trying to understand how to retrieve full (absolute, not relative, not starting with ~/) page URLs in a multilingual website. Sitefinity knows about them. All I want is get the URL Sitefinity is using for a page.
In case I have the page id (Me.LinkPageGUID in the code below), this is what I've come up with:
Dim LinkPage As PageNode = App.WorkWith.Pages.LocatedIn(Fluent.Pages.PageLocation.Frontend).Where(Function(p) p.Id = Me.LinkPageGUID).Get.FirstOrDefault()Dim FullDomain As String = Page.Request.Url.Scheme & System.Uri.SchemeDelimiter & Page.Request.Url.Host & (If(Page.Request.Url.IsDefaultPort, "", ":" & Page.Request.Url.Port))Dim PageUrl As String = Page.ResolveUrl(LinkPage.GetFullUrl(Threading.Thread.CurrentThread.CurrentUICulture, True))Me.Link1.NavigateUrl = FullDomain & PageUrlHi Arno,
You could use this method to get a PageNode back:
/// <summary>/// Get a page url/// </summary>/// <param name="id"></param>/// <returns></returns>public static string GetPageUrl(Guid id) var result = string.Empty; var currentLanguage = Thread.CurrentThread.CurrentUICulture; var s = ObjectFactory.Resolve<UrlLocalizationService>(); var pm = PageManager.GetManager(); try if (s != null) var pageNode = pm.GetPageNode(id); if (pageNode != null) result = s.ResolvePageUrl(pageNode, currentLanguage); catch (ItemNotFoundException) return result; catch (NullReferenceException) return result; return result;var url = GetPageUrl(pageId);if (url == null) return;var absoluteUrl = VirtualPathUtility.ToAbsolute(url);Sorry, I see you are using VB.NET.
Then it would be like this:
''' <summary>''' Get a page url''' </summary>''' <param name="id"></param>''' <returns></returns>Public Shared Function GetPageUrl(id As Guid) As String Dim result = String.Empty Dim currentLanguage = Thread.CurrentThread.CurrentUICulture Dim s = ObjectFactory.Resolve(Of UrlLocalizationService)() Dim pm = PageManager.GetManager() Try If s IsNot Nothing Then Dim pageNode = pm.GetPageNode(id) If pageNode IsNot Nothing Then result = s.ResolvePageUrl(pageNode, currentLanguage) End If End If Catch generatedExceptionName As ItemNotFoundException Return result Catch generatedExceptionName As NullReferenceException Return result End Try Return resultEnd FunctionDim url = GetPageUrl(pageId)If url Is Nothing Then ReturnEnd IfDim absoluteUrl = VirtualPathUtility.ToAbsolute(url)Thanks a lot Daniel! That makes more sense to me than my LINQ attempt. And I decided to store the domain as an app setting in web.config and get it from there if I need it.
Now, I hope someone knows how to get the forum page. Still haven't figured out that one.