Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Jarno 21 posts 152 karma points
    Dec 03, 2019 @ 10:24

    Casting iContent to iPublishedContent in v8

    Hi all,

    Is there anyone that has a solution for casting iContent to iPublishedContent in v8?

    In v7 is was using this extension method but it don't works in v8.


  • Dave de Moel 121 posts 573 karma points c-trib
    Dec 04, 2019 @ 08:52
    Dave de Moel

    Hey man,

    After the conversation yesterday I decided to check it out a bit with the snapshotservice and I figured out what changed thanks to Nathan Woulfe on the Slack community.

    Seems they slightly changed how to get preview IContent content. Here is an excerpt from my content api package:

    public class PreviewApiController : UmbracoApiController
        private readonly Lazy<IContentResolver> _contentResolver;
        private readonly IPublishedSnapshotService _publishedSnapshotService;
        private readonly IUserService _userService;
        private readonly IContentService _contentService;
        public PreviewApiController(Lazy<IContentResolver> contentResolver, IPublishedSnapshotService publishedSnapshotService, IUserService userService, IContentService contentService)
            _contentResolver = contentResolver;
            _publishedSnapshotService = publishedSnapshotService;
            _userService = userService;
            _contentService = contentService;
        public IHttpActionResult Get(Guid id)
            _publishedSnapshotService.EnterPreview(_userService.GetUserById(-1), _contentService.GetById(id).Id);
            IPublishedContent content = _publishedSnapshotService.CreatePublishedSnapshot(
            ContentModel contentModel = _contentResolver.Value.ResolveContent(content);
            return Ok(contentModel);

    I just verified this works in Umbraco 8.3

Please Sign in or register to post replies

Write your reply to: