Reputation: 1706
So i was looking a lot on several topics here and learningrazorpages. but i cannot figure something out.
so on my setup i have area
Identity
/pages
/account
/login
services
.AddMvc(cfg =>
{
cfg.UseCentralRoutePrefix(new RouteAttribute(path));
})
on my controllers this works like a charm. But it looks like on my razor pages this is not honored.
so now i have to write this in my *.cshtml.
@page "~/PREFIX/identity/account/login2"
but i dont want to write this on all my pages. can i do this easy with razor conventions on an area?
.AddRazorPagesOptions(options => {...}); ???
Upvotes: 2
Views: 1544
Reputation: 93133
Razor Pages routing is configured via conventions and is not affected by the application model that is used in MVC. In order to apply a custom convention that affects all pages in an area, you can target the area and root folder with something like the following:
services.AddMvc()
.AddRazorPagesOptions(o =>
{
o.Conventions.AddAreaFolderRouteModelConvention("Identity", "/", pageRouteModel =>
{
foreach (var selectorModel in pageRouteModel.Selectors)
selectorModel.AttributeRouteModel.Template = "PREFIX/" + selectorModel.AttributeRouteModel.Template;
});
});
This example configures a convention for the root (using /
) of the Identity
area, which iterates over all of the existing templates and adds PREFIX/
to each.
Upvotes: 5