Copied to clipboard

Flag this post as spam?

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

  • illumi 10 posts 75 karma points
    Feb 19, 2019 @ 22:34

    How to instantiate umbracohelper in my provider

    I am adding extra properties to a provider created by a colleague. I need the umbhelper to check for memberaccess to a resultpage in a search. Unfortunately i get an "value cannot be null" on the "public UmbracoHelper umbHelper = new UmbracoHelper(UmbracoContext.Current);" line.

    How should i instantiate the helper so i can use it properly?

    Eternally grateful for any help possible.

    enter image description here

    enter image description here

  • illumi 10 posts 75 karma points
    Feb 20, 2019 @ 12:34

    Solved. I moved the instantiation inside the CreateObject class.

  • Chris Evans 137 posts 353 karma points c-trib
    Feb 20, 2019 @ 21:21
    Chris Evans

    Just one thing that may be useful: it seems that your CreateObject method is already being passed an instance of the UmbracoHelper (see the helper parameter).

    So you can probably just use that by changing that line as follows:

    bool restricted = umbHelper.IsProtected(result.Path)

    to be:

    bool restricted = helper.IsProtected(result.Path)

    and then just remove the umbHelper instantiation and property altogether.

    That's probably a better way of doing it, because creating instances of UmbracoHelper from UmbracoContext.Current is discouraged:

Please Sign in or register to post replies

Write your reply to: