Create packing that is using composer is not worki...
# help-with-umbraco
b
Hi, I'm trying to create a new Umbraco package that should improve security for multiple Umbraco instances. So I try to create a reusable package for this purpose. I've create a new package and a test project and it is recognised as installed package. However, the code isn't fired. In the package App_Plugins/xxx I created a .cs file. This is the content:
Copy code
using System.Linq;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Extensions;

namespace HttpHeaderSecurity.App_Plugins.HttpHeaderSecurity
{
    public class HttpHeadersComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.Configure<UmbracoPipelineOptions>(options => options.AddFilter(new UmbracoPipelineFilter("HttpHeaders", postRouting: app => app.Use(async (context, next) =>
            {
                // Add the security headers
                context.Response.Headers["X-Frame-Options"] = "SAMEORIGIN";
                // (... more here)

                await next();
            }))));
        }
    }
When I add the public class 'HttpHeadersComposer ' to the program.cs directly, the headers are added. So.. how to trigger this code from a package?
j
App_Plugins is for static files, if you need c# code you should release it as a nuget package
b
Okay, thanks @Jemayn ! I thought I did, as I make a .nupkg file in DevOps. But to work locally, I've a simple test project with my package using a command like; `dotnet new umbraco -n CustomWelcomeDashboardProject -p CustomWelcomeDashboard After a while I realised I missed a simple stap: needed to add a App_Code folder. When I added that folder and placed the C# code in there, it seems to be working.
6 Views