Orchardcore: Decoupled CMS routing issue using Razor Pages

Created on 8 Apr 2019  路  12Comments  路  Source: OrchardCMS/OrchardCore

I am trying to create a custom module (ForumModule) with a Host with Decoupled CMS.

This is my Host system startup.cs

  public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .AddOrchardCms()
            .AddMvc();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseOrchardCore();
        }
    }

and this is the Startup at my ForumModule

    public class Startup : StartupBase
    {
        public override void ConfigureServices(IServiceCollection services)
        {
        }

        public override void Configure(IApplicationBuilder app, IRouteBuilder routes, IServiceProvider serviceProvider)
        {
        }
    }

This is the layout of the project

module-1

The problem is that neither /ForumModule/ nor /ForumModule/About nor /ForumModule/Contact works.

However /About and /Contact works! This is surprising and I wonder if it's supposed to be that way. Because if I just use services.AddOrchardCore instead of add.AddOrchardCms(), the reverse situation happens.

Contact.cshtml is just consisted of this code so there is no overriding the path at the page level.

@page

<h1>Contact from Forum Module</h1>

module-2

The whole project is here https://github.com/dodyg/practical-aspnetcore/tree/master/projects/orchard-core/cms

Most helpful comment

@dodyg okay no problem, just tried this project.

  • I removed the OC.Application.Targets reference, you don't need it if you reference OC.Application.Cms.Targets.

  • Then i removed AddMvc(), just kept AddOrchardCms().

  • The ForumModule manifest file was missing so i copy pasted a Manifest.cs.

  • Then, i followed the same step as above, run the setup where i selected the blank site recipe, go to the admin and enable the ForumModule and so on.

  • Then all links with the module name work as expected. To make working routes without the module name you would have to use razor pages route helpers, as we do in our demo module.

  • In your _ViewStart you can just use Layout = "_Layout"; then the layout is naturaly found in the views shared folder, the layout can also be put in the Pages/Shared folder, then the _ViewImports.cshtml and the _ViewStart.cshtml can be put under the Pages folder.

  • Finally, i removed the Watch Include in your project file, and i was still able to update the views in live while in debug mode.

All 12 comments

Hi, I did a Razor Pages sample a while ago. You might want to have a look:
Orchard Core with Razor Pages decoupled

@jtkech is this related to #2549?

@hishamco hmm, yes because around razor pages, but #2549 is more related to home pages and razor page layouts discovering. Normally these issues have been fixed and there is a testing project OC.Application.Pages in our solution.

About this issue, AddOrchardCms call itself our AddMvc which is applied at the tenant level, then it returns the host level service collection. So, applying AddMvc on AddOrchardCms, as it is done here, re-add all mvc services at the host level.

So, @dodyg try to just remove the AddMvc() that you apply on AddOrchardCms.

If they have been fixed .. we need to close them 馃槉

It doesn't work.

With AddMvc()

with-add-mvc

Without AddMvc()

with-no-mvc

@dodyg okay.

Just saw the link to your repo, i can't right now but i will try it this night directly from your repo.

@dodyg

Just tried your project under the C:\Sources\practical-aspnetcore\projects\orchard-core\routing-3\Host folder of your repo, all was working fine.

When your app reference OC.Application.Mvc.Targets, as it is in your repo, it means that you don't use the full cms and it is not intended that you use AddOrchardCms(). In this case you have to rather use AddOrchardCore() and then AddMvc() on it, as it is done in your repo. So, i first tried your Host application as it is and all was working.

Then, in your app i referenced OC.Application.Cms.Targets and just used AddOrchardCms() without AddMvc() because it is called by AddOrchardCms().

  • I also created a wwroot folder with a placeholder file so that Image Sharp doesn't fail.

  • Then, i add to run a setup where i selected the SaaS recipe.

  • Then, i add to login and go to the admin.

  • Then, i had to enable the Forum and the Ticket modules.

  • Then, all links were working fine.

Hi @jtkech,

Thank you for taking a look at this case. Unfortunately you checked on the wrong code. The code I was referring to is https://github.com/dodyg/practical-aspnetcore/tree/master/projects/orchard-core/cms

actual

The Host project already uses the CMS target to

    <ItemGroup>
        <PackageReference Include="OrchardCore.Application.Cms.Targets" Version="1.0.0-beta3-71077" />
        <PackageReference Include="OrchardCore.Application.Targets" Version="1.0.0-beta3-71077" />
        <PackageReference Include="Microsoft.AspNetCore.App" />
    </ItemGroup>

And the Forum project uses

 <ItemGroup>
    <PackageReference Include="OrchardCore.Module.Targets" Version="1.0.0-beta3-71077" />
    <PackageReference Include="OrchardCore.Mvc.Core" Version="1.0.0-beta3-71077" />
  </ItemGroup>

With only AddOrchardCms() nothing works

the-code

output

With AddOrchardCms().AddMvc(), some page works, but in an unexpected ways

I am not sure whether this is by design or not. Because if my module was using MVC, the /ForumModule/ or /ForumModule/About or /ForumModule/Contact, they would have worked.

the-code-2

output-2

@dodyg okay no problem, just tried this project.

  • I removed the OC.Application.Targets reference, you don't need it if you reference OC.Application.Cms.Targets.

  • Then i removed AddMvc(), just kept AddOrchardCms().

  • The ForumModule manifest file was missing so i copy pasted a Manifest.cs.

  • Then, i followed the same step as above, run the setup where i selected the blank site recipe, go to the admin and enable the ForumModule and so on.

  • Then all links with the module name work as expected. To make working routes without the module name you would have to use razor pages route helpers, as we do in our demo module.

  • In your _ViewStart you can just use Layout = "_Layout"; then the layout is naturaly found in the views shared folder, the layout can also be put in the Pages/Shared folder, then the _ViewImports.cshtml and the _ViewStart.cshtml can be put under the Pages folder.

  • Finally, i removed the Watch Include in your project file, and i was still able to update the views in live while in debug mode.

Oh it seems that I missed a lot of steps. Awesome. It works now. Thank you!

Hi,
can you write the solution and the main steps to get it working

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chillibug picture chillibug  路  4Comments

aghili371 picture aghili371  路  3Comments

superluminalK picture superluminalK  路  4Comments

khoshroomahdi picture khoshroomahdi  路  4Comments

deanmarcussen picture deanmarcussen  路  3Comments