Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Fixes #66
Browse files Browse the repository at this point in the history
When a page is unpublished, the URL is "#", which isn't a valid URI,
so an error is thrown. Now we detect this and use a fallback URI
from the current request.
  • Loading branch information
leekelleher committed Feb 13, 2019
1 parent f074dee commit 1e063a7
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int pageId)
// Ensure PublishedContentRequest exists, just in case there are any RTE Macros to render
if (UmbracoContext.PublishedContentRequest == null)
{
var pageUrl = page.UrlAbsolute();

// If the page is unpublished, then the URL will be empty or a hash '#'.
// Use the current request as a fallback, as we need to give the PublishedContentRequest a URI.
if (string.IsNullOrEmpty(pageUrl) || pageUrl.Equals("#"))
{
pageUrl = string.Concat(Request.RequestUri.GetLeftPart(UriPartial.Authority), "/#", pageId);
}

#pragma warning disable CS0618 // Type or member is obsolete
var pcr = new PublishedContentRequest(new Uri(page.UrlAbsolute()), UmbracoContext.RoutingContext);
var pcr = new PublishedContentRequest(new Uri(pageUrl), UmbracoContext.RoutingContext);
#pragma warning restore CS0618 // Type or member is obsolete

UmbracoContext.PublishedContentRequest = pcr;
Expand Down

0 comments on commit 1e063a7

Please sign in to comment.