I need to build a CMS like website.
I have a Backend (admin website) where users can create or update pages for the Frontend (it will be 2 differents websites but both are .Net Core 6 MVC)
I've already done that with Asp.Net MVC by directly manipulating the RouteCollection of the Front. The Backend was calling an action on the Front that was creating/updating the needed route for the purpose of url rewriting)
Here how I define Route url of all Pages in Front :
var pages = _pageService.GetAll();
foreach (CmsPage page in pages)
{
routeCollection.MapRoute(
name: $"page-{page.PageId}",
url: page.url,
defaults: new
{
controller = "PageController",
action = "Detail",
id = page.PageId,
}
);
}
This way, in Razor, I can easily list all page's link like this :
@foreach (CmsPage page in Pages)
{
<a href="@Url.RouteUrl("page-" + page.PageId)">@page.Title</a>
}
If Users in Backend want to change the slug of a Page, the Backend call the Front so he can change the needed entry in the RouteCollection and update the slug :
protected void UpdateRouteFromRouteTable(string routeName, string newUrl)
{
// Get the route by name
var route = RouteTable.Routes[routeName];
using (RouteTable.Routes.GetWriteLock())
{
((Route)(route)).Url = newUrl;
}
}
By doing this the slug of the page is updated on the Front.
THIS is no more possible in .Net Core (can't access routeTable) but I need to achieve the same goal maybe with some kind of dynamics routing.
Where should I look ? I read about DynamicRouteValueTransformer but it doesn't seems to be what I'm looking for, neither seems to be Microsoft.AspNetCore.Rewrite.RewriteContext...
Any hints ?
Thx a lot