Copied to clipboard

Flag this post as spam?

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


  • Andrew 52 posts 234 karma points
    Jan 15, 2022 @ 17:03
    Andrew
    0

    Not sure what I'm doing wrong with UmbracoContext.Content.GetByRoute

    Hi,

    I've created a controller and I inject IUmbracoContextFactory

    When I use Content.GetByRoot with a culture parameter, I get content of the default language rather than the culture I requested.

     using (var cref = this.umbracoContextFactory.EnsureUmbracoContext())
            {
                var contentX = cref.UmbracoContext.Content.GetByRoute("/some-page-url",culture:lang);
    
                return Ok(contentX);
            }
    

    Any suggestions about what might be wrong?

  • Andrew 52 posts 234 karma points
    Jan 15, 2022 @ 18:15
    Andrew
    100

    I found this https://our.umbraco.com/forum/umbraco-8/96665-get-content-based-on-accept-language#comment-310873

    It uses a variationContextAccessor and seems to work

    this.variationContextAccessor.VariationContext = new VariationContext(lang);

Please Sign in or register to post replies

Write your reply to:

Draft