OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.37k stars 2.38k forks source link

Unexpected behaviour of razor pages tag helper #11725

Closed Cinnam00n closed 2 years ago

Cinnam00n commented 2 years ago

Issue

After following documentation instructions on setting up decoupled CMS the behaviour of asp-page tag helper breaks.

For example, in the _Layout.cshtml file we have a navlink

<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>

which instead of redirecting to the Privacy page, redirects to

https://localhost:7181/Admin/OrchardCore.Settings/Admin/Index?page=%2FPrivacy

Expected Behaviour

Page navigation works the same way as in Razor Pages project template.

ns8482e commented 2 years ago

Everything in OC is module (area) including host web project.

If you project name is OrchardCore.Cms.Web then tag helper to refer to Privacy page for OrchardCore.Cms.Web/Pages/Privacy.cshtml should be referred in tag helper as

<a class="nav-link text-dark" asp-area="OrchardCore.Cms.Web" asp-page="/Privacy">Privacy</a>
Skrypt commented 2 years ago

@ns8482e While what you are saying is right; I think normally it should resolve a frontend route when we are not passing any area on a View that is rendered on the frontend. The same goes for a backend View.

Cinnam00n commented 2 years ago

@ns8482e now that you say it, it feels obvious but I spent a good deal of time trying to find a solution using documentation, without success. It might be a good idea to specify it explicitly in the tutorial on setting up the decoupled CMS site.

ns8482e commented 2 years ago

I guess if you don’t define area then default behavior of the tag helper takes current serving controller’s area or first match

here the issue is because of having tag helper is in layout and serving controller vary, so it’s better to define area

Skrypt commented 2 years ago

Is it not related with the DI priority?

ns8482e commented 2 years ago

@Skrypt it's ASP.NET CORE's default behavior - if area is omitted - It would take area of executing controller if area and controller is omitted it will take area and controller of current executing action

Skrypt commented 2 years ago

Ok then it is by design and we should close the issue.