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
    1 week ago
    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 1390 posts 9427 karma points MVP 5x c-trib
    1 week ago
    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 56 posts 234 karma points
    1 week ago
    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
    7 days ago
    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