Copied to clipboard

Flag this post as spam?

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


  • Rail Way 2 posts 22 karma points
    Jan 12, 2021 @ 16:20
    Rail Way
    0

    How to get page content in UmbracoApiController by umbracoUrlAlias

    Hi, everyone. I have a trouble to get page content when I use umbracoUrlAlias instead of normal url. Actually below is good when I use normal url path. IPublishedContent m = UmbracoContext.Content.GetByRoute(urlSegment);

    But this is not working (m will be null) if I use umbracoUrlAlias.

    In another hand, page is correctly displayed when I use both of normal and alias.

    How can I get page content by Alias ?

  • Marc Goodson 2138 posts 14321 karma points MVP 8x c-trib
    Jan 12, 2021 @ 19:06
    Marc Goodson
    0

    Hi Rail

    The core Umbraco Content Finder 'ContentFinderByUrlAlias'

    does it like this:

    https://github.com/umbraco/Umbraco-CMS/blob/2bfef741914297c802bc6c77cc48780d7534f920/src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs#L54

    essentially looping through all descendants of the site looking for an umbracoUrlAlias value that matches the alias being searched for.

    Is that what you are after?

    regards

    Marc

  • AddWeb Solution Pvt. Ltd 109 posts 360 karma points
    Jan 13, 2021 @ 11:17
    AddWeb Solution Pvt. Ltd
    0

    Hello,

    In order to get the umbracoUrlAlias value...

    var urlAlias = item.Value<string>("umbracoUrlAlias");
    

    Also, UmbracoContext.Current.ContentCache.GetByRoute(string url) could do, what you want. (umbracoUrlAlias will not be in uppercase, all URL's in umbraco are lowercase check that)

  • Rail Way 2 posts 22 karma points
    Jan 14, 2021 @ 02:47
    Rail Way
    0

    Hello, @AddWeb Solution Pvt.Ltd

    In below line;

    UmbracoContext.Current.ContentCache.GetByRoute(string url) 
    

    Can you access to UmbracoContext.Current ? I can't see Current property in UmbracoContext.

Please Sign in or register to post replies

Write your reply to:

Draft