Copied to clipboard

Flag this post as spam?

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


  • Martin Damm 4 posts 93 karma points
    Oct 13, 2020 @ 06:03
    Martin Damm
    0

    Using UmbracoHelper with IPackageAction

    The problem:

    I am trying to use UmbracoHelper inside my custom package action. The reason I want to use it is because I need to access the root node to alter its permissions. The examples linked in the documentation uses hardcoded Guids but that won't work for me. Using the code sample beneath throws an CS7069: Reference to type 'HttpContextBase' claims it is defined in 'System.Web' but it could not be found

    The code:

    public class CustomPackageAction : IPackageAction
    {
        private readonly IUmbracoContextFactory _context;
    
        public CustomPackageAction(IUmbracoContextFactory context)
        {
            _context = context;
        }
    
        public string Alias() => "CustomPackageAction";
    
        public bool Execute(string packageName, XElement xmlData)
        {
            using (UmbracoContextReference cref = _context.EnsureUmbracoContext())
            {
                var cache = cref.UmbracoContext.Content;
            }
        }
    }
    

    Does anyone know what might be the solution?

    Kind regards

  • Martin Damm 4 posts 93 karma points
    Oct 13, 2020 @ 07:32
    Martin Damm
    100

    I found the solution, so I will leave this here for posterity.

    The reason it failed was because I had added a Class Library with target framework .Net Standard 2.0. Upon creating a new Class Library targeting .Net Framework 4.7.2 and referencing a few .dll files from my Umbraco project I was up and running.

Please Sign in or register to post replies

Write your reply to:

Draft