.Configure<UmbracoPipelineOptions>(options =>
{
options.AddFilter(new UmbracoPipelineFilter(nameof(ProductController))
{
Endpoints = app => app.UseEndpoints(endpoints =>
{
var categoryPages = umbracoContext.Content
.GetByXPath($"//{CategoryPage.ModelTypeAlias}")
.ToList();
var allLanguages = _localizationService.GetAllLanguages().ToList();
foreach (var content in categoryPages)
{
foreach (var language in allLanguages)
{
var culture = language.CultureInfo.Name;
endpoints.MapControllerRoute(
content.Name(_variationContextAccessor, culture),
content.Url(culture) + "/{sku}",
new { Controller = "Product", Action = "Index" });
}
}
})
});
});
Obviously this doesn't work because of the 'Singleton' instance of a IUmbracoBuilder in a IComponent. And injecting stuff in a IComposer is not supported either.
Even when I do as below the problem still exists because of when stuff is registered i.e. Composers seems to run before the registring of IPublishedContentCache. And IUmbracoContextAccessor is not available yet.
[Weight(int.MaxValue)]
public class ProjectComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
var serviceProvider = builder.Services.BuildServiceProvider();
var contentCache = serviceProvider.GetRequiredService<IPublishedContentCache>();
var categoryPages = contentCache
.GetByXPath($"//{CategoryPage.ModelTypeAlias}")
.ToList();
//builder.Services.Configure<UmbracoPipelineOptions>(options =>
//{
// options.AddFilter(new UmbracoPipelineFilter(nameof(ProductController))
// {
// Endpoints = app => app.UseEndpoints(endpoints =>
// {
// foreach (var content in categoryPages)
// {
// endpoints.MapControllerRoute(
// "ProductController_"+ content.Name(culture).StripWhitespace().StripAccents(),
// content.Url(culture) + "/{sku}",
// new { Controller = "Product", Action = "Index" });
// }
// })
// });
//});
}
}
Dynamic custom routes
Hi.
After reading this I get how to do custom routes. However, we want dynamic custom routes.
https://our.umbraco.com/Documentation/Reference/Routing/custom-routes
For example:
/any-url/any-route/category-page/product-page
So the code I sort of want to use is this:
Obviously this doesn't work because of the 'Singleton' instance of a
IUmbracoBuilder
in aIComponent
. And injecting stuff in aIComposer
is not supported either.Does anyone have an idea?
Even when I do as below the problem still exists because of when stuff is registered i.e. Composers seems to run before the registring of
IPublishedContentCache
. AndIUmbracoContextAccessor
is not available yet.Seem to be what ever I do the 'MainDom' or 'UmbracoContext' is not available yet. No matter the order I put this in.
Managed to solve it with IContentFinder.
is working on a reply...