IContentLoader.GetChildren and expired pages

Vote:
 

Hi.


I have a question regarding how EPiServer is handling expired pages via the ContentLoader (if at all)


I use GetChildren occasionally to extract pages from specific parents and so on - but it seems like that GetChildren cannot filter out pages that are expired, so I have to handle it manually afterwards. Is this correct?

From what I can see/ find - a page with expiration has a StopPublished date and if that date is less than / equal to my timestamp - the page is expired. Is this the correct or is there an alternative property I need to / can check instead?


Regards, and thanks in advance.

#178773
May 22, 2017 10:24
Vote:
 

It is partly correct. The ContentLoader doesn't handle it when you use GetChildren to load.

However the recommended way is to use the IPublishedStateAssessor:

_contentLoader.GetChildren<EntryContent>(parentReference).Where(_publishedStateAssessor.IsPublished)

The PublishedStateAssessor will consider a lot of things including if the content hasn't been published yet, if it has expired, if it is part of a project and so on.

It is also adviced to use the Assessor instead of implementing it all yourself because Episerver might add/change how it behaves to match new functionality in the CMS.

Best Regards

Erik

#178788
May 22, 2017 15:37
Vote:
 

Thank you. I'll take a look at the PublishedStateAssessor, because right now I'm using the CheckPublishedStatus on PageData when it's applicable for that Content - but it has some issues that looks to be much easier handled using your example.


Thanks a lot :)

#178789
Edited, May 22, 2017 15:39
Vote:
 
<p>I favor doing FilterForVisitor() after fetching lists instead of cherry picking filters. Will allow you to set up better caching strategies as well.</p> <p><a href="/documentation/Class-library/?documentId=cms/9/8E7ED7FC">http://world.episerver.com/documentation/Class-library/?documentId=cms/9/8E7ED7FC</a></p>
#178797
May 22, 2017 17:28
Vote:
 

Yes indeed FilterForVisitor is the best to use inside the site as it filters out by VisitorGroups as well.

It does require having a current user in the context and won't work otherwise.

I didn't see any indication in OP about what the context is, hence i gave the general filter.

Kind Regards

Erik

#178815
May 23, 2017 12:54
Vote:
 

I've changed my code to use the PublishedStateAssessor and it looks to work very nicely for what I need it to do, so thanks a million :)


It was primarily regarding publish / expiration to begin with, but that filter looks interesting for some of our other usage - so I'll keep that in mind.

#178822
May 23, 2017 14:41
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.