Copied to clipboard

Flag this post as spam?

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


  • karen 186 posts 461 karma points
    Mar 16, 2013 @ 19:04
    karen
    0

    get node by umbracoUrlAlias ul

    I am using the uComponents method to get a node from the URL:

         umbraco.presentation.nodeFactory.Node node = uQuery.GetNodeByUrl(request.RawUrl);

    and then get some properties of the page

    However that is not working if the requested url (from request.RawUrl) is the umbracoUrlAlias

    Example:

    - the full page is http://localhost/landing-pages/touchpoint-1--woohoo!.aspx

    - the umbracoUrlAlias has the page at http://localhost/woo-hoo

    using the umbracoUrlAlias, the node.id = -1, so it's not finding the correct node on the call.

     

    So is there a way to get the node from the umbracoUrlAlias?  I need to check a property on the page before it is served so I can redirect or not for certain pages for mobile devices.

    This is umbraco v 4.0.4.2

  • karen 186 posts 461 karma points
    Mar 16, 2013 @ 21:20
    karen
    0

    Some more thoughts - this is using the older umbraco xml synatx with <node><data> etc.

    So I tested this in an xsl to find the ID of the node I want and it works.

    <xsl:variable name="topLevel" select="$currentPage/ancestor-or-self::node [@level=1]"/>
    woohoo umbraco id=<xsl:value-of select="$topLevel//node[ data[@alias='umbracoUrlAlias'] = 'woo-hoo' ]/@id"/><Br/>

     

    Now I am trying to translate that into using uQuery.GetNodesByXPath but I can't figure out the correct syntax, it keeps coming up with 0 nodes

    I've tried this various things:

    var nodes = uQuery.GetNodesByXPath("//*[ data[@alias='umbracoUrlAlias'] = 'woo-hoo' ]");

    var nodes = uQuery.GetNodesByXPath("//*/node[ data[@alias='umbracoUrlAlias'] = 'woo-hoo' ]");

    any ideas on what that syntax should be?

     

  • karen 186 posts 461 karma points
    Mar 16, 2013 @ 21:57
    karen
    100

    ok, finally found a solution.

    This worked:

    var nodes = uQuery.GetNodesByXPath("//node[ data[@alias='umbracoUrlAlias'] = 'woo-hoo' ]");

    so to translate, you have to remove the / from the beginning of RawUrl

    string sUrl = request.RawUrl.Substring(1);
    var nodes = uQuery.GetNodesByXPath("//node[ data[@alias='umbracoUrlAlias'] = '" + sUrl + "' ]");

    and then check if nodes.Count > 0 and get nodes[0]

  • Charles Afford 1163 posts 1709 karma points
    Mar 17, 2013 @ 10:25
    Charles Afford
    0

    Hi, why are you using uQuery to get the Node by Url?  Charlie :)

  • karen 186 posts 461 karma points
    Mar 17, 2013 @ 17:51
    karen
    0

    Charlie - how else would I do it?   When I google ' how to get umbraco node by url ' that is the only solution I could find.

    If you know of a better solution - please share!

  • Stephen 767 posts 2268 karma points c-trib
    Mar 17, 2013 @ 19:02
    Stephen
    0

    What  version of Umbraco is that?

    In _theory_ starting with 4.11 it should work 'out of the box' including supporting umbracoUrlAlias.

    Stephan

  • Charles Afford 1163 posts 1709 karma points
    Mar 17, 2013 @ 19:19
    Charles Afford
    0

    Hi, Karen was just wondering why you were choosing the url or the id for instance?  Charlie :)

  • karen 186 posts 461 karma points
    Mar 17, 2013 @ 19:33
    karen
    0

    Stephan - in the original post - This is umbraco v 4.0.4.2.  Not sure what version of uComponents.

    Charlie - I am not sure what you are asking?  Each page has individual settings, so I need figure out what the settings for the page they are asking for are.

     

     

  • Charles Afford 1163 posts 1709 karma points
    Mar 17, 2013 @ 19:39
    Charles Afford
    0

    ah ok, its becuase i think i was told that uQuery.GetNodeByUrl(request.RawUrl); is not encrypted, thus it is not tamper proof if it is a public faceing website.   

  • 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