Copied to clipboard

Flag this post as spam?

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


  • Peter Nielsen 159 posts 257 karma points
    Jul 08, 2019 @ 09:02
    Peter Nielsen
    0

    uQuery.GetNodeIdByUrl() in Umbraco 8

    Hi

    I'm trying to get a node by its url or path. Before v8 you could do it by uQuery.GetNodeIdByUrl("/"); but now I can't find the equivalent method.

    I'm trying to call it inside af Umbraco Web API if that makes any difference :)

    /Peter

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Jul 08, 2019 @ 09:23
    Marc Goodson
    100

    Hi Peter

    There is the GetByRoute method in 'IPublishedContentCache'

    https://github.com/umbraco/Umbraco-CMS/blob/853087a75044b814df458457dc9a1f778cc89749/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs#L34

    So wondering if somethign like this would work in your APIController?

     IPublishedContent matchingRouteContentItem = UmbracoContext.ContentCache.GetByRoute("/",false);
    

    regards

    Marc

  • Peter Nielsen 159 posts 257 karma points
    Jul 08, 2019 @ 11:37
    Peter Nielsen
    0

    Hi Mark

    Thank you. That was exactly was I was looking for :)

    But in my case second parameter should be true, else I can't find subpages.

    /Peter

  • Damien Holley 180 posts 541 karma points
    Nov 16, 2020 @ 02:43
    Damien Holley
    0

    This should now be

     IPublishedContent matchingRouteContentItem = UmbracoContext.Content.GetByRoute("/",false);
    
Please Sign in or register to post replies

Write your reply to:

Draft