New Sitecore Publishing Targets in Containers

We have a Sitecore system running in containers, and we wanted to add a new publishing target. This is another copy of the WEB database; ours is called “preview”, and it is so that editors can check published content before it goes live.

I followed Sitecore’s documentation about how to do this – and do take note of steps 4 and 5. They’re new, and I missed them to begin with:

  • In the App_Data\items\ folder, make a copy of the Web folder.
  • Rename the copy of the folder and the .dat file inside it. Use the database name (for example, web_preview) instead of web for the folder name and the file name (so the filename is similar to items.web_preview.dat).

It turns out that’s important – without it you’ll get an exception on startup.

However, after doing that, we still had problems with our preview database; the CM server kept throwing an exception.

Continue reading “New Sitecore Publishing Targets in Containers”
New Sitecore Publishing Targets in Containers

System.Buffers references in Sitecore Nuget Packages

So, we keep seeing issues on different projects with the error:

Could not load file or assembly ‘System.Buffers, Version=4.0.x.x

The error can sometimes seem intermittent, or just plain baffling. If you then examine the /BIN directory, and look at the properties (right click on the dll, and look at the file properties) of System.Buffers, you’ll find that it’s a wrong version; it’s not what is referenced in web.config (remembering that you may have an Assembly binding redirect in place) at all.

I’m tired of digging out details for myself/my colleagues, so here’s what’s happening…

Continue reading “System.Buffers references in Sitecore Nuget Packages”
System.Buffers references in Sitecore Nuget Packages

Using web.config transforms on assembly binding redirects

Right, I keep having to do this, and keep having to look this up, so here it is.

If you want to do a web transform for an assembly binding redirect it can be a bit tricky. The assembly details are in an <assemblyIdentity /> element, and the <bindingRedirect /> is its sibling. Yeah, I don’t know why it was designed this way; I’m assuming alcohol was involved. Yes, having the oldVersion and newVersion attributes in the same element at the assembly’s identity would be much simpler.

Anyway, it is what it is. An alternative is to replace the entire <dependentAssembly /> element, but the locator becomes a bit more fiddly. Still, it works. See this example – the locator on the parent element is checking the name of the child assemblyIdentity.

<dependentAssembly xdt:Transform="Replace" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='System.Runtime')">
    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
Using web.config transforms on assembly binding redirects

Carousels are killing our Core Web Vitals scores

So, we’re all familiar with the Core Web Vitals scores, right? Just in case we’re not, lets recap. These are scores that Google uses to just the speed of your page. It’s more than just “How much data” does the page use, or “When is the DOM ready”, but also includes things like “When is the content painted on the page” and “How much does stuff shift as the page is loaded”.

This is actually really good, as these are much better metrics; people want your page to read, and these metrics focus on that.

So, one of the things I’ve noticed is that a number of our customers are not getting great scores for the Largest Contentful Paint (LCP) – and this seems to be due to a particular bugbear of mine – carousels.

Continue reading “Carousels are killing our Core Web Vitals scores”
Carousels are killing our Core Web Vitals scores

Email Regular Expression

One of my colleagues asked a question that I’ve heard dozens of times over my career…

What’s a good regular expression for validating email addresses.

Sadly, due to poor standards, poor implementation choices, and just the sheer age of Email, this is a surprisingly tough problem.

The best way to validate an email address is to email it, and get the user to do something. That’s not really feasible if it’s someone just filling in a form.

Failing that, I came up with:

^[^@\s]+@[^@\s]+\.[^@\s]+$

This is the same as suggested by Microsoft, which is gratifying. You can see the logic of it here.

Email Regular Expression

Logging client actions near page Unload

I had an interesting problem; we wanted to log stuff that was happening on a client’s browser. Fair enough, we can use AJAX to do that. However, this had a twist – we wanted to log events that were happening immediately before the page might be redirected to a new location. In other words, the page might unload, and a new page load. What I found was the messages from just before the page unloaded might not be sent to the server; as the page was unloading, the AJAX requests were not being performed. I wondered what I could do about this. Continue reading “Logging client actions near page Unload”

Logging client actions near page Unload

Don’t be Lax about your SameSite cookies

We have a customer who is using Sitecore and the SagePay Pi service to take credit card payments. They were using a multi-page Sitecore Forms form, and weirdly their confirmation emails couldn’t use field values from the first pages of the form. Eventually, we found that the problem was due to the the user’s session being lost, but only if the user was using 3D-secure, and a recent browser. Here’s why…

Continue reading “Don’t be Lax about your SameSite cookies”

Don’t be Lax about your SameSite cookies

Random discovery: Why the 13th Hex character of Guids is ‘4’

I noticed something strange in Sitecore; for most of my nodes (not the Sitecore node!), the 13th Hex character of the identifying GUID is ‘4’.

I had a list of about 50 of these, and my eye was drawn to the pattern. Now, I thought Guids were entirely random, except that the chance of 50 page template IDs all having a 4 at that character was infinitesimal.

Weird. Except it turns out that they’re not random. I had no idea that there are different versions of guids, or than that character defined the version of the GUID.

This requires a test, so I wrote a program to print Guid.NewGuid() a lot:

All of them are 4s.

So:

  • GUIDs aren’t entirely random.
  • They might not be very random at all, looking at some of the other GUID versions.
  • Which is why they shouldn’t be used as a source of entropy for encryption.
  • I still have things to learn.
Random discovery: Why the 13th Hex character of Guids is ‘4’

Keeping the size of of Sitecore Azure Backups under control

I’ve written before about Azure Backup fails due to Content Testing Screenshots not clearing and the resulting problems with backup size.

That’s not the whole problem though.

Sitecore made some effort to configure some directories to be outside the home folder of the app services, and therefore not subject to backup – but there’s still a lot that shouldn’t be in the backup. Continue reading “Keeping the size of of Sitecore Azure Backups under control”

Keeping the size of of Sitecore Azure Backups under control