Query PageData by URL of the PageNode
Native API
To find a particular PageData by the URL of the PageNode, you use the GetPageNodes method and filter based on the UrlName property. Use the following code sample:
C#
using System.Linq;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;
namespace SitefinityWebApp
{
public class QueryPages_FindPagebyUrl_NativeAPI
{
public PageData FindPagebyUrlNativeAPI(string urlName)
{
PageManager pageManager = PageManager.GetManager();
PageNode pageNode = pageManager.GetPageNodes().Where(pN => pN.UrlName == urlName).FirstOrDefault();
if (pageNode == null)
{
return null;
}
return pageNode.GetPageData();
}
}
}
Fluent API
To find a particular PageData by the URL of the PageNode, you use the plural page facade to ensure that the PageNode with the specified UrlName exists. Then, you use the Get method of the plural page facade to get the PageNode. To get the PageData, you use the Page property in the following:
C#
using System.Linq;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Pages.Model;
namespace SitefinityWebApp
{
public class QueryPages_FindPagebyUrl_FluentAPI
{
public PageData FindPagebyUrlFluentAPI(string urlName)
{
PageData pageData = null;
var count = 0;
App.WorkWith().Pages().Where(pN => pN.UrlName == urlName).Count(out count);
if (count != 0)
{
pageData = App.WorkWith().Pages().Where(pN => pN.UrlName == urlName).Get().First().Page;
}
return pageData;
}
}
}
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.