Copied to clipboard

Flag this post as spam?

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

  • Mus'ab 141 posts 354 karma points notactivated
    Sep 30, 2019 @ 17:41

    How to get and render unpublished nodes using IContentFinder ?

    I have unpublished nodes in the back office they were unpublished in order to reduce the cash file and to increase the navigation speed, but i couldn't render the unpublished nodes.

    I used the following example to handle the nodes that are beneath the "2017" which is unpulbished.

    public class MyContentFinder : IContentFinder
       public bool TryFindContent(PublishedRequest contentRequest)
        // handle all requests beginning /woot...
        var path = contentRequest.Uri.GetAbsolutePathDecoded();
        if (!path.StartsWith("/2017"))
            return false; // not found
        var content = contentRequest.UmbracoContext.Content.GetByRoute(path);
        if (content == null) return false; // not found let another IContentFinder in the collection try to find a document
        // render that node
        contentRequest.PublishedContent = content;
        return true;
        throw new NotImplementedException();

    What I noticed, I could not get unpulbished content by GetByRoute() with a given path.

    so the below line could not do the what I wanted :

     contentRequest.PublishedContent = content;

    Any insight ?

  • Bo Jacobsen 356 posts 1536 karma points
    Sep 30, 2019 @ 20:18
    Bo Jacobsen

    Hi Mus'ab.

    If you wanna find unpublished content then you need to to use the IContentService, but it will also return IContent. So you need to convert it to IPublishedContent somehow, wich i dont recommend.

    The downside of this is that IContentService make one or more database calls, so you rather wanna use the cashe. If you feels like your cashe is slow it might be because of some customcode.

  • Marc Goodson 1154 posts 7697 karma points MVP 5x c-trib
    Sep 30, 2019 @ 20:39
    Marc Goodson

    This is for V7, but we wrote an article about how to retrieve 'archived' content in an Umbraco site:

    that might provide some inspiration...

    But as Bo says, you won't find it in the Umbraco Cache when it's unpublished...

    but you can create your own content object that implements IPublishedContent from Examine or another location (we used a custom database table) or even using the ContentService...

    and your IContentFinder can return your custom IPublishedContent object...



Please Sign in or register to post replies

Write your reply to: