IPageRetriever Returns Unpublished Items

Nate Axtell asked on February 18, 2025 17:03

In Kentico 13.0.157, I'm using the IPageRetriever to return a set of pages to use in the footer of my site. I have a page that was unpublished back in 2023 that is periodically being returned and displayed in the footer list. My use of IPageRetriever is quite simple so I'm not sure what the cause of the problem is. Has anyone else encountered this with IPageRetriever and figured out a way to prevent it from happening again? I've encountered this issue with other instances of IPageRetriever on this website, but this example is the most visible since it is seen on every page of the site.

Here's a code sample that shows the relatively simple use of RetreiveAsync.

var regions = await _pageRetriever.RetrieveAsync<Region>(
    query => query
    .Columns(
        nameof(Region.NodeSiteID),
        nameof(Region.NodeID),
        nameof(Region.NodeGUID),
        nameof(Region.NodeAliasPath),
        nameof(Region.NodeLevel),
        nameof(Region.NodeOrder),
        nameof(Region.DocumentName),
        nameof(Region.DocumentCulture))
    .Path(path, PathTypeEnum.Children));

    return regions.Select(r => new MenuItemViewModel<Region>
    { 
        RegionNode = r,
        PageUrl = _pageUrlRetriever.Retrieve(r).AbsoluteUrl
    });

Correct Answer

James de Boer answered on October 1, 2025 15:51

Late answer but are you caching the footer in some way?

If so and you view a page in the admin site when the cache is refreshing the _pageRetriever will get back unpublished pages. See https://docs.kentico.com/13/custom-development/working-with-pages-in-the-api which states:

the correct version of pages is retrieved depending on whether the content is displayed on the live site or in the administration interface.

So this version is cached and shown in the live site.

Just a possibility as I ran into this scenario today.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Nate Axtell answered on October 7, 2025 14:41

Thanks for your reply. This was the cause of my issue. Whenever a content admin previewed a page on the Admin site, that page was getting cached with unpublished content.

Early in my development I had missed disabling IProgressiveCache via the Cache property when in Preview mode. I had followed an example higher on the below page missing the section on how to support Preview mode properly. I was able to add in, cs.Cache = !websiteChannelContext.IsPreview, to fix all of my issues.

https://docs.kentico.com/documentation/developers-and-admins/development/caching/data-caching#preview-mode-and-caching

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.