I spent a little time yesterday building a simple little PageProvider. For the record, it was an RSS PageProvider that would read an RSS fead and present the entries as pages... Not very complicated or special, but it needed to be done. It's going to be one of the exercises in the new advanced developer course for EPiServer. So, what was the problem...well...my provider worked, but only when I refreshed the page. The initial request would come up empty, but when I refreshed the page it would show up as it should...
So...I walked over to Enes at the development team and asked him. He was responsible for creating the XML PageProvider that can be downloaded at http://world.episerver.com. So I guess he should know. Well, he didn't... So I gave him my code for debugging and he started working. Hmmm...this blog entry is more about Enes working than me, but who cares... It was my code...
After a bit of stepping through the code, we (yes WE, I was sitting next to Enes helping/looking) found out that thepages were removed in a filter. THe default filters in the system filter based on if the page is published and publication date. Well, I did set the pages as published so it wasn't that. So there was only the publication date filter left. And sure enough...there the ugly little "feature" was. When initializing PageData object using the helper implementation in PageProviderBase, the PublishDate is set to, more or less, DateTime.Now. But when the system compares the dates, it compares against the time when the request came to the server. So it ends up in the following situation:
Request comes to server and time is "logged". Then the system checks the cache and finds no pages, so it asks the PageProvider for pages. The PageProvider creates the pages, initializing them using the helper method, which sets the PublishDate to the current time. It then returns the pages, which are then filtered, checking the StartPublish time against the request time. Since that comparison doesn't work, the pages are filtered away and the collection comes back empty. On the next request, the pages are fetched from the cache and filtered. But this time the publication date is ok.
So, the quick and dirty fix to this is to set the StartPublish property to DateTime.Now.AddMinutes(-1). That takes care of the problem, however ugly it is... This will be fixed in a future service pack. Enes has already got on the case, and probably already fixed it... So you just have to wait for the SP...