Copied to clipboard

Flag this post as spam?

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


  • Matthew Scerri 4 posts 45 karma points
    Mar 05, 2014 @ 12:26
    Matthew Scerri
    1

    Getting Node from Url

    Good afternoon,

    I am currently in need of a way to get a page id from a Url. I have found plenty of old topics relating to this issue, but none that provided an answer that seemed to work for me.

    If I've got this Url: /sample/url/node/ the only way I could find to fetch the associated node's id would be to do something like:

    Umbraco.TypedContentSingleAtXPath("//*[@urlName='sample']/*[@urlName='url']/*[@urlName='node']").Id

    However, something tells me that I'm probably over complicating it.

    Any help would be very much appreciated!

    Thanks,

    Matt

  • Tommy Albinsson 121 posts 254 karma points
    Mar 22, 2014 @ 14:09
    Tommy Albinsson
    100

    Hey,

    You can use umbraco.uQuery.

    Node node = uQuery.GetNodeByUrl("/home.aspx");
    
  • Wojciech Tengler 96 posts 207 karma points
    May 20, 2016 @ 11:17
    Wojciech Tengler
    0

    Look out when you want to use it in Umbraco 6.2.6. My website is stoping when I call this method.

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Jul 04, 2018 @ 17:17
    Alex Skrypnyk
    1

    If you're using Umbraco 4.11 or later, there are a new set of APIs that allow you to retrieve strongly-typed content (as opposed to dynamic - which can be frustrating when trying to evaluate types when debugging).

    UmbracoContext.Current.ContentCache.GetByRoute(string url) should do what you want.
    
  • 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