I had a problem recently with a Sitecore system I was working on. We had 4 machines involved – a development server, a content management server (CM), and two content delivery (CD) servers. The problem was, for the ‘News Search’ page we would get different number of items on the CD servers than the CM or development systems.
CM and Dev would return 8 items for a search of news from 1st April to 30th April. The CDs would return 54 items…
Using Luke, I checked that the query running on the development box would retrieve the same items from the indexes on the CD servers. It did; therefore the items had been correctly published and were up to date. The issue had to lie in the C# code. Stepping through the code for that I noticed that the dates were being handed in via the DateTime.TryParse() method. This set alarm bells ringing. That method tries to parse the date in the current thread’s locale. If this were, say, US English (en-us) rather than the presumed GB English (en-gb) then the dates we were searching between would actually be the 4th of January and, well, not-parsable. If the date wasn’t parsable then the code just used today’s date instead – and such a search would return 54 items.
So the problem was the region settings. I checked this on my development system by changing the regional settings for the current user, and it worked. However, this didn’t work for the CM/CD servers.
When I went to IIS on my development box I discovered (to my horror) that my application pool was running under the ‘Adminstrator’ account. This is bad; I can only assume that it’s something that I did, but I don’t like it.
It would explain why changing my locale changed how Date.TryParse() worked, though – I was changing the profile that the application pool was using
Fortunately, my live servers used a more sensible account – NETWORK SERVICE :
I’d rather that I was using ApplicationPoolIdentity, but I was told to use Network Service for other reasons. Anyway, the question then became “How do I set the Locale for the Network Service account“? It took a bit of digging, but under Control Panel > Regions and Language > Administrative Tab it does mention setting the System Account locale settings:
My settings on the CM server was set to UK for everything, but on the CD servers they were set to US:
Using the checkboxes I could copy over my current (UK) formats…
… Perform an IIS Reset, and my CD servers worked the same as my dev and CM servers.
Obviously, the higher level issue is the use of DateTime.TryParse() of an unknown format of language, but that’s a problem for someone else.