1

I've been trying to add Piranha CMS (version 10) to my existing website, which is an ASP.Net Core MVC app on .Net 6. It currently uses Areas to hold content for different topics (Music, Games, etc), and I'd like to have a Blog area that runs the Piranha site (and manager). However, I'm just unable to figure out how I configure Startup.cs to let this happen.

Below is the Configure method of my Startup.cs file (I haven't moved to the single Program.cs style yet). I've created a 'Blog' Area, and copied the CMSController class there along with the template Views and Models, but I'm not sure that is right.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IApi api)
    {
        ...

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "GitHub",
                template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
            routes.MapRoute(
                name: "Games",
                template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
            routes.MapRoute(
                name: "Blog",
                template: "{area:exists}/{controller=Cms}/{action=Index}/");
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        // Piranha stuff
        App.Init(api);
        new ContentTypeBuilder(api)
            .AddAssembly(typeof(Startup).Assembly)
            .Build()
            .DeleteOrphans();

        // Configure Tiny MCE
        EditorConfig.FromFile("editorconfig.json");
        
        app.UsePiranha(options =>
        {
            options.UseManager();
            options.UseTinyMCE();
            options.UseIdentity();
        });
    } 

My ConfigureServices method has some additional configuration as well:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages()
            .AddRazorRuntimeCompilation()
            .AddPiranhaManagerOptions(); ;

        ...

        services.AddAuthorization(options =>
        {
            options.AddPolicy("Administrators", new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .RequireClaim("role", "Administrators")
                .Build());
            options.AddPolicy("PiranhaRoles", new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .RequireClaim("piranharoles", "PiranhaRoles")
                .Build());
            ...
        });

        services.AddPiranha(options =>
        {
            options.UseFileStorage(naming: Piranha.Local.FileStorageNaming.UniqueFolderNames);
            options.UseImageSharp();
            options.UseCms();
            options.UseManager();
            options.UseTinyMCE();
            options.UseMemoryCache();
            options.UseEF<SQLServerDb>(db =>
                db.UseSqlServer(connectionString));
        });
    }

When I start up the app and go to /Blog, it doesn't return any view (which I expect considering there is no real Index page. /Manager doesn't show either. So my question is: How do I configure the routing in my Startup class to host the Piranha CMS app at mywebsite.com\Blog (and the manager at mywebsite.com\Blog\Manager)?

Bonus question: Why do I have to add services.AddAuthorization with the Piranha roles in my ConfigureServices method? There must be a way to have the required roles added without having to specify all of them individually this way.

benhorgen
  • 1,928
  • 1
  • 33
  • 38
Heffay
  • 11
  • 1
  • 3

0 Answers0