EpiServer: How to check if a page exists?

Is there a way to gracefully check if a page exists in EpiServer CMS 5 (given the integer pageId) without , to catch PageNotFoundException, the cast

DataFactory.Instance.GetPage(pageReference)

(EpiServer will happily create a PageReference using a non-existing pageId).

Of course, I can check if the page exists without throwing an exception or doing a massive loop?

+3
source share
3 answers

[EPiServer CMS 5 R2 SP2] No, bypassing the page cache, and this is more expensive than catching an exception.

+6
source

I like to make a trap in the extension method:

public static bool TryGetPage(this PageReference pageReference, out PageData pd)
{
    try
    {
        pd = DataFactory.Instance.GetPage(pageReference);
        return true;
    }
    catch (Exception)
    {
        pd = null;
        return false;
    }
}
0
source

There is a static PageReference method that should help:

PageReference.IsNullOrEmpty(pageLink)
-3
source

Source: https://habr.com/ru/post/1723467/


All Articles