diff --git a/src/Umbraco.Web.Common/Middleware/PreviewAuthenticationMiddleware.cs b/src/Umbraco.Web.Common/Middleware/PreviewAuthenticationMiddleware.cs index 55001ca28c..0748f5cbb4 100644 --- a/src/Umbraco.Web.Common/Middleware/PreviewAuthenticationMiddleware.cs +++ b/src/Umbraco.Web.Common/Middleware/PreviewAuthenticationMiddleware.cs @@ -51,17 +51,23 @@ public class PreviewAuthenticationMiddleware : IMiddleware // If we've gotten this far it means a preview cookie has been set and a front-end umbraco document request is executing. // In this case, authentication will not have occurred for an Umbraco back office User, however we need to perform the authentication // for the user here so that the preview capability can be authorized otherwise only the non-preview page will be rendered. - if (cookieOptions.Cookie.Name is not null && - request.Cookies.TryGetValue(cookieOptions.Cookie.Name, out var cookie)) + if (cookieOptions.Cookie.Name != null) { - AuthenticationTicket? unprotected = cookieOptions.TicketDataFormat.Unprotect(cookie); - ClaimsIdentity? backOfficeIdentity = unprotected?.Principal.GetUmbracoIdentity(); - if (backOfficeIdentity != null) + var chunkingCookieManager = new ChunkingCookieManager(); + var cookie = chunkingCookieManager.GetRequestCookie(context, cookieOptions.Cookie.Name); + + if (!string.IsNullOrEmpty(cookie)) { - // Ok, we've got a real ticket, now we can add this ticket's identity to the current - // Principal, this means we'll have 2 identities assigned to the principal which we can - // use to authorize the preview and allow for a back office User. - context.User.AddIdentity(backOfficeIdentity); + AuthenticationTicket? unprotected = cookieOptions.TicketDataFormat.Unprotect(cookie); + ClaimsIdentity? backOfficeIdentity = unprotected?.Principal.GetUmbracoIdentity(); + + if (backOfficeIdentity != null) + { + // Ok, we've got a real ticket, now we can add this ticket's identity to the current + // Principal, this means we'll have 2 identities assigned to the principal which we can + // use to authorize the preview and allow for a back office User. + context.User.AddIdentity(backOfficeIdentity); + } } } }