NullReferenceException in Sitecore.ExperienceExplorer.Business.Pipelines .HttpRequest.EnableExperienceModePipeline.Process

Recently I was upgrading a site to Sitecore 8.2.1, and I received the following error:

Okay, WTF? There’s not a lot of information about this error, and I’d never seen it before. I ended up doing my usual trick – decompiling Sitecore to see what this method does. Here’s what I found…

…and the bit underlined in red set my “stupidity radar” screaming. This line is:

string database = SiteContext.GetSite(Settings.Preview.DefaultSite).SiteInfo.Database;

If GetSite() returns null, you’ll get a null reference exception, because they didn’t bother to check the returned variable before trying to use its ‘SiteInfo’ property.

It does offer a clue, though. Our upgraded system lacks a site called ‘website‘. That is, in our config, under the <sites> node, there is no <site ... > called ‘website‘. However, the DefaultSite setting in Sitecore.config still had its default value of ‘website‘.

We changed it to the name of our site, and this error was resolved.

NullReferenceException in Sitecore.ExperienceExplorer.Business.Pipelines .HttpRequest.EnableExperienceModePipeline.Process

Sitecore shell wouldn’t work over HTTPS

I was working at a customer recently who’s Sitecore instance wasn’t accessible over HTTPS. It was a single server, and the site itself was working just fine over HTTPS, so that begged the question – why?

The error we were getting was:

Sitecore.Context.ContentDatabase returns null.

We were using HTTPS, and it’s worth noting that rather than redirecting all HTTP traffic to HTTPS with IIS, they were using C# code and a Response.Redirect() call in their page itself, which is… unusual. It also means that HTTP traffic to Sitecore shell is not redirected – the content page layout isn’t loaded, so their redirect wouldn’t happen.

Eventually, I found the following in a patch file:

<site name="shell">
<patch:attribute name="port">80</patch:attribute>
</site>
<site name="login">
<patch:attribute name="port">80</patch:attribute>
</site>

Interesting. Shell and login were being tied to port 80 – but HTTPS uses 443.

I removed this patch, and suddenly Sitecore was available over HTTPS again.

 

Sitecore shell wouldn’t work over HTTPS

For Sitecore, specify MongoDB connections in lower case…

You wouldn’t think this was 2017, but here we are again struggling with upper and lower case again.

In a Sitecore instance I had the following connection string to MongoDB:

<add name="analytics" connectionString="mongodb://mongo.ourserver.local/XXXX_analytics" />

However, something was wrong with the instance; installing packages on it didn’t work (which is VERY strange – why does it need MongoDB? That doesn’t make sense! Anyway…)

Looking in the log, I found:

36404 00:00:26 ERROR Exception when executing agent processing/taskAgent
Exception: MongoDB.Driver.MongoCommandException
Message: Command 'findAndModify' failed: exception: db already exists with different case already have: [xxxx_tracking_live] trying to create [XXXX_tracking_live] (response: { "errmsg" : "exception: db already exists with different case already have: [xxxx_tracking_live] trying to create [XXXX_tracking_live]", "code" : 13297, "ok" : 0.0 })
Source: MongoDB.Driver
at MongoDB.Driver.Operations.CommandOperation`1.Execute(MongoConnection connection)

Ah. So MongoDB would happily:

  • Try to find the repository with the name containing capitals (“XXXX_analytics”)
  • Correctly fail (repository doesn’t exist), and then create the repository with the name rendered to lower case (“xxxx_analytics”)
  • Try to find the repository with the name containing capitals again (“XXXX_analytics”)
  • Incorrectly fail to find the repository due to the case difference, and then try to create the repository a second time with the name renadered to lower case.

This is stupid. If one method ignores case, so should the others.  I don’t mind which way it works – obey or ignore case – but it needs to be consistent.

For Sitecore, specify MongoDB connections in lower case…

Turn off Auth on Solr

Okay, so you probably shouldn’t be doing this – but should you install Solr using the Bitnami stack – like I usually would – it will ask you to set up a usename and password to connect with.

This is a good thing (much better than MongoDB’s “Insecure by default” configuration) – but what if you don’t want it (e.g. for your shared dev Solr instance)?

  • Edit \solr-xxxx\apache-solr\conf\solr.conf
  • Set AuthType to “None”
  • Remove “Require User ” line
  • Restart service.

That should do it.

Turn off Auth on Solr

Securing MongoDB (Brief Notes)

So, Sitecore uses MongoDB, a product that has an interesting approach to security. When you install it, by default, it doesn’t have any. By Default:

  • Mongo does not require authentication
  • Communication is unencrypted
  • In fact, if you can connect to it, you can bugger about with the data

This is, ahem, “suboptimal”. It is, however, possible to to set it up. Options:

  • Restrict IP address access at the firewall. Good practice, to be honest, and not covered here.
  • Configure to use SSL
  • Configure to use a username/password in connection strings

Continue reading “Securing MongoDB (Brief Notes)”

Securing MongoDB (Brief Notes)

Sitecore Serialization – System.ArgumentException: Illegal characters in path

So, I was trying to use Sitecore Serialisation, and I got the following error:

System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.IsPathRooted(String path)
at Sitecore.Data.Serialization.PathUtils.MapItemPath(String itemPath, String root)

capture-serialization-page

Joy. Sadly, this pad doesn’t give a clue what the problem item actually is. The log files don’t show an exception – but I can see the last item processed, and it looks funny:

capture-of-log-file

So, if that’s the item throwing the exception then a) serialisation isn’t logging the exception, which sucks, and b) some items in this tree have newline or carriage return characters (\n or \r)

To try and find these, I ran SQL against the database…

SELECT * FROM [MASTER].[dbo].[Items]
where Name like '%' + CHAR(10) + '%'
or Name like '%' + CHAR(13) + '%'

This found a bunch of items with \r in their names. Lord knows how they were put there. I suspect copy and paste from some of the actual content.

Sitecore Serialization – System.ArgumentException: Illegal characters in path