Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Currently if you press the preview button only that node will be in preview mode. All other content is just the published version. We've got a huge website and we do many customizations in it. You might have heard of it ;-). For our preview we need all the content to be in preview mode. We know this might be slow, but we still need this.
Anyone got some suggestions for this? I already have the code to convert an IContent to an IPublishedContent. I could check if the website is in preview mode and than use that, but maybe there are better ways to achieve this :-).
Not only the current node will be in preview, but also all child nodes. So by clicking preview on the highest node in the tree it seems that you can run your entire site in preview.
Will do some more experiments :-).
Also make sure to upgrade to Umbraco 7.4.2 if you want to preview protected pages: http://issues.umbraco.org/issue/U4-4219#comment=67-27355
Preview works in the frontend, but I would also like preview to work in the backend. So if I'm in preview mode it also shows those URLs in the backoffice. For now I checked the Umbraco source and it looks like I can check if the preview cookie is available. Would that be enough?
Could you replace the ContentFinderByNiceUrl with your own version that hits the ContentService rather than the cache?
Na. That won't work. Sorry - you've need to replace the UmbracoHelper as well I'd guess. You've got me.
The UmbracoHelper is only used in the frontend where InPreviewMode is already true. For the backoffice URLs replacing the ContentFinderByNiceUrl might actually work. But it's not the content finder that I need to replace but the UrlProvider.
OK, I've not properly understood where exactly in the back office you're referring to but I hope you make some progress with that approach.
I mean the URLs that you see in the backoffice. An unpublished node has no URL, but in preview mode it does, but still isn't displayed.
Well could you create a custom property editor which just displays what the URL is? You it would just get the UrlName of all ancestors, add it's own based on string.ToUrlSegment() (in Umbraco.Core), and join with a '/'. It's not the same as the Url but if it is just for information?
Already got something like that, but it's a complex website and I need to get the URLs from the UrlProviders.
I got it working by having a custom property editor which get's the URLs from the front of the website. If the website is in preview it will return all the URLs. Even of unpublished ones.
This looks cool!
Can you share the code for this?
The UrlPreview code can be found in the 1-1 multilingual example: https://our.umbraco.org/projects/developer-tools/1-1-multilingual-example/
Since preview for all content only works if you click preview on the highest node I wrote some code for that which can be triggered from every node.
You can call this from a custom property editor. It will get the highest node and use that for preview.
/// The url preview api controller.
public class UrlPreviewApiController : UmbracoAuthorizedApiController
/// Update preview for the entire website.
/// The <see cref="HttpResponseMessage"/>.
public HttpResponseMessage UpdatePreview()
var result = new HttpResponseMessage(HttpStatusCode.OK);
// Get the highest node in the tree.
// If we use this id for preview it will preview the entire website.
var websiteId = this.GetWebsiteId();
// Update the preview so we can see the saved changes.
/// Checks if the user is currently in preview mode and if so will update the preview content for this item.
/// If it's not in preview a new one will be created.
/// <param name="contentId">
/// The content id.
/// This code uses some obsolete methods, but parts are copied from the Umbraco source and we keep it the same.
private void UpdatePreviewContext(int contentId)
// Get the preview id from the cookie.
var previewId = this.Request.GetPreviewCookieValue();
// If we have a GUID from the cookie use that.
var existingPreview = Guid.TryParse(previewId, out id);
// If we don't have GUID from the cookie yet create a new one.
id = Guid.NewGuid();
// Create the preview.
var d = new Document(contentId);
var pc = new PreviewContent(this.UmbracoUser, id, false);
pc.PrepareDocument(this.UmbracoUser, d, true);
// Create a new preview cookie if we don't have one.
/// Get the id of the website node. Don't use the ContentRepository because that only works with published content.
/// The id.
private int GetWebsiteId()
var websiteContentType = this.Services.ContentTypeService.GetContentType(Website.ModelTypeAlias);
var website = this.Services.ContentService.GetContentOfContentType(websiteContentType.Id).FirstOrDefault();
if (website != null)
Is it simply because your 2nd browser that it doesn't work in doesn't have the preview cookie set?
Both browsers had the preview cookie set. The problem was that we were testing with the same user and that didn't work. So when testing in multiple browsers you should also login with different Umbraco users.
Also pretty sure there's a setting somewhere to turn on full site preview... Or at least there was something along those lines at some point in time ;) i can see if i can find anything tomorrow if you don't beat me to it.
Preview for the full site would be cool, but my solution at https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/78849-preview-all-content#comment-252857 also works fine :-).
@shannon any chance you found how to turn on full-site preview at site level via settings?
We are in the same situation but need to preview unpublished pages as anonymous users
I blogged about how you can preview all the content. It also has a working example: http://24days.in/umbraco-cms/2016/umbraco-edge-case-stories/#preview
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted