Copied to clipboard

Flag this post as spam?

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


  • Mimi 21 posts 91 karma points
    Aug 08, 2022 @ 12:03
    Mimi
    0

    how can i return current.umbracohelper in umbraco-v9

    Hi.

    I have the following code which does not work in umbraco v.9:

      public static UmbracoHelper GetUmbracoHelper() {
      if ( HttpContext.Current != null ) {
        return Current.UmbracoHelper;
      }
    
      return null;
    }
    

    What I have done:

       public  UmbracoHelper GetUmbracoHelper()
        {
            if (_accessor.HttpContext != null)
            { 
                return _umbracoHelper;
            }
    
            return null;
        }
    

    So I have injected UmbracoHelper but iam getting error that says "AssignedContentItem = '_umbracoHelper.AssignedContentItem' threw an exception of type 'System.InvalidOperationException'" Do someone know what I am doing wrong or missing ?

  • Huw Reddick 1932 posts 6722 karma points MVP 3x c-trib
    Aug 08, 2022 @ 15:41
    Huw Reddick
    0

    what exactly were you planning on using umbracohelper for exactly? I believe there are other ways of achieving it in your classes rather than using umbraco helper

  • Marc Goodson 2157 posts 14435 karma points MVP 10x c-trib
    Aug 08, 2022 @ 18:44
    Marc Goodson
    1

    Hi Fa

    There is a good article here about how to access UmbrocoHelper and UmbracoContext in various different places in v9 that might be helpful

    https://our.umbraco.com/documentation/implementation/Services/

  • Mimi 21 posts 91 karma points
    Aug 10, 2022 @ 09:01
    Mimi
    0

    Hi Marc Goodson

    The article was helpful, it did resolve the issue i had. Thank you :)

  • 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