Copied to clipboard

Flag this post as spam?

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


  • Tomasz 22 posts 96 karma points
    Oct 15, 2019 @ 23:08
    Tomasz
    0

    Umbraco 8 get by route

    Anyone knows where I can find Get By Route content finder? Trying to see what I can do within Umbraco API Controller, but there's no such method?

  • Marc Goodson 2157 posts 14435 karma points MVP 9x c-trib
    Oct 17, 2019 @ 18:47
    Marc Goodson
    0

    Hi Tomasz

    If your API controller inherits from UmbracoApiController (which in turn inherits UmbracoApiControllerBase)

    https://github.com/umbraco/Umbraco-CMS/blob/9c06ef83e217affbce51c1d6682f10914be2b400/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs

    You'll have access to the PublishedContentCache through the UmbracoContext property of the controller, this in turn has a 'Content' property that is of type IPublishedContentCache which is where the GetByRoute() method lives:

     public class SuperApiController : UmbracoApiController
        {
            [System.Web.Http.HttpGet]
            public IEnumerable<string> GetListOfThings()
            {
                // here is GetByRoute...
                UmbracoContext.Content.GetByRoute();
    
            }
        }
    

    regards

    Marc

  • Tomasz 22 posts 96 karma points
    Oct 17, 2019 @ 19:50
    Tomasz
    0

    Face... palm... I should have tried to investigate the methods there, instead of getting stuck on Umbraco.(...) class...

    Thank you Marc!

  • 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