diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs
index 15a931957c..8cbb0bb0fc 100644
--- a/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs
+++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs
@@ -106,11 +106,19 @@ namespace Umbraco.Web.PublishedCache
{
var guidUdi = contentId as GuidUdi;
if (guidUdi == null)
- throw new InvalidOperationException("UDIs for content items must be " + typeof(GuidUdi));
+ throw new ArgumentException($"Udi must be of type {typeof(GuidUdi).Name}.", nameof(contentId));
+
+ if (guidUdi.EntityType != UdiEntityType)
+ throw new ArgumentException($"Udi entity type must be \"{UdiEntityType}\".", nameof(contentId));
return GetById(preview, guidUdi.Guid);
}
+ ///
+ /// Gets the entity type.
+ ///
+ protected abstract string UdiEntityType { get; }
+
///
/// Gets content at root.
///
diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs
index c927644817..4475f6893e 100644
--- a/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs
+++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
@@ -21,6 +22,8 @@ namespace Umbraco.Web.PublishedCache
: base(umbracoContext, cache)
{ }
+ protected override string UdiEntityType => Constants.UdiEntityType.Document;
+
public override IPublishedContent GetById(bool preview, Guid contentKey)
{
if (InnerCache is PublishedContentCache cc)
diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedMediaCache.cs
index 0b4ccc18c4..6ab50f14fa 100644
--- a/src/Umbraco.Web/PublishedCache/ContextualPublishedMediaCache.cs
+++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedMediaCache.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
@@ -21,6 +22,8 @@ namespace Umbraco.Web.PublishedCache
: base(umbracoContext, cache)
{ }
+ protected override string UdiEntityType => Constants.UdiEntityType.Media;
+
public override IPublishedContent GetById(bool preview, Guid contentKey)
{
if (InnerCache is PublishedMediaCache cc)