1
votes

We are using Sitecore 8 in our project, which has two different sites.

When trying to retrieve the home item for one of these sites, it seems to be unreliable:

var database = Factory.GetDatabase("Web");
var homeItem = database.GetItem(new ID("{FAF3904C-4BE4-ED80-891A-DFEE0A4C18C5}"));

When the site has just been restarted in IIS, or when the Sitecore cache has been emptied, sometimes the homeItem variable is null.

It seems that the database object does provide items for one site (the "current" site, corresponding with our request URL) but it doesn't provide items for the other site.

On subsequent requests for the other site, it seems that items for both sites are available. And sometimes, even after restarting IIS or clearing the Sitecore cache, all items are readily available from the start. (I haven't found a number of steps which reproduces the problem consistently.)

I'm guessing that some kind of caching somewhere (probably outside the Sitecore cache) is happening, but I have no clue what exactly it might be.

Does anybody know why database.GetItem could return null sometimes for items that do exist, but might belong to a different site than the current one? And more important: how can I get items from the database with the guarantee that items from all sites are available?

1

1 Answers

1
votes

Short answer:

It turns out that this had to do with security. The current request's user didn't have access to the items of the other site.

More info:

The reason that I did not find this immediately when I used the SecurityDisabler in an early test, is that our project is using a custom AuthorizationProvider which apparently didn't cooperate properly with the SecurityDisabler.

Also, it is still unclear why we did have access to all items on subsequent requests for the second site, but I think this might have to do with caching on some level.