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 149 posts 206 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 1451 posts 9716 karma points MVP 5x 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 149 posts 206 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 126 posts 425 karma points
    Nov 16, 2020 @ 02:43
    Damien Holley
    0

    This should now be

     IPublishedContent matchingRouteContentItem = UmbracoContext.Content.GetByRoute("/",false);
    
  • 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