Query full page URL
In this article, you learn how to query the full URL of a page. The overall algorithm is to use the GetSiteBySiteMapRoot method to get the site to which the page belongs. Then, you use the UrlLocalizationService to resolve the language-specific URL of the page and use some string manipulation to construct the full URL.
If you are using PageNode to represent your page objects, follow this sample:
C#
using System.Globalization;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Localization.UrlLocalizationStrategies;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Multisite;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.Services;
namespace SitefinityWebApp
{
public partial class RetrieveFullPageURLExample
{
public string RetrievePageAbsoluteURL(PageNode pageNode, CultureInfo culture)
{
string url = string.Empty;
MultisiteContext multisiteContext = SystemManager.CurrentContext as MultisiteContext;
UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
ISite site = multisiteContext.GetSiteBySiteMapRoot(pageNode.RootNodeId);
if (site != null)
{
string domain = (site.RequiresSsl ? "https://" : "http://") + site.LiveUrl;
url = domain + s.ResolveUrl(pageNode.GetUrl(culture), culture).Trim('~');
}
return url;
}
}
}
If you are using PageSiteNode to represent your page objects, follow this sample:
C#
using System;
using System.Globalization;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Localization.UrlLocalizationStrategies;
using Telerik.Sitefinity.Multisite;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Web;
namespace SitefinityWebApp
{
public partial class RetrieveFullPageURLExample
{
public string RetrievePageAbsoluteURL(PageSiteNode pageNode, CultureInfo culture)
{
string url = string.Empty;
MultisiteContext multisiteContext = SystemManager.CurrentContext as MultisiteContext;
UrlLocalizationService s = ObjectFactory.Resolve<UrlLocalizationService>();
ISite site = multisiteContext.GetSiteBySiteMapRoot(Guid.Parse(pageNode.RootNode.Key));
if (site != null)
{
string domain = (site.RequiresSsl ? "https://" : "http://") + site.LiveUrl;
url = domain + s.ResolveUrl(pageNode.GetUrl(culture), culture).Trim('~');
}
return url;
}
}
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.