Copied to clipboard

Flag this post as spam?

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


  • Jay 425 posts 652 karma points
    Aug 07, 2016 @ 18:56
    Jay
    0

    Exclude Preview mode from IContentFinder

    Hi All,

    I'm using IContentFinder similar to the implementation below https://gist.github.com/alindgren/4f8e47d9b2d769137be3

    Was wondering if there's a way i can exclude the Preview mode within the IContentFinder as currently when you clicked on the preview button on a content node, it just shows 404 not found due to the path does not contains a language from the implementation above.

    Appreciate any help

    Thanks a million

  • Mike 23 posts 86 karma points
    Sep 26, 2016 @ 09:52
    Mike
    0

    I've come across this same problem, and I've come up with an admittedly hacky solution to it.

    When a node is previewed, I take the path and check to see if it can be parsed as an integer, as the URL is of the structure "http://yoursite.com/1234.aspx". If the first part is an integer, I treat it as a preview item.

    The key part is the call to GetById.. One of the overload signatures has a bool property that allows you to state if you want the preview item. Set this to true, and you get the preview item as IPublishedContent.

    var path = contentRequest
        .Uri
        .GetAbsolutePathDecoded();
    
    var parts = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
    
    int nodeId;
    
    if(parts.Length == 1 && int.TryParse(parts[0], out nodeId))
    {
        var contentCache = UmbracoContext
            .Current
            .ContentCache;
    
        var content = contentCache.GetById(true, nodeId);
    
        contentRequest.PublishedContent = content;
    
        return true;
    }
    

    As I said above, I don't feel that this is as clean a solution as it could be, so I'd love to hear if there is a better way of doing this.

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Sep 26, 2016 @ 10:11
    Jeroen Breuer
    0

    You could also preview all the content of the website. Than the IContentFinder should not return a 404. See this example: https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/78849-preview-all-content#comment-252857

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies