Hi All
I’m currently setting up a new site and attempting to setup a custom controller for the sitemap. I’ve followed the example here , and the composer methods are being hit, but the controller methods aren’t, I simply get ‘no umbraco documents exists for the url’ . Am I missing something obvious?
My Composer:
public class StartupComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.Configure<UmbracoPipelineOptions>(options =>
{
options.AddFilter(new UmbracoPipelineFilter(nameof(SitemapXmlController))
{
Endpoints = app => app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
"Sitemap Xml",
"/sitemap",
new { Controller = "SitemapXml", Action = "Index" });
endpoints.MapControllerRoute(
"Sitemap Xml 2",
"/sitemap.xml",
new { Controller = "SitemapXml", Action = "Index" });
})
});
});
builder.Services.Configure<UmbracoRequestOptions>(options =>
{
options.HandleAsServerSideRequest = httpRequest => httpRequest.Path.StartsWithSegments("/sitemap.xml");
});
}
}
My Controller:
public class SitemapXmlController : UmbracoPageController, IVirtualPageController
{
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
public SitemapXmlController(ILogger<UmbracoPageController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor) : base(logger, compositeViewEngine)
{
_umbracoContextAccessor = umbracoContextAccessor;
}
[HttpGet]
public IActionResult Index()
{
// Render the sitemap.cshtml template
return View("/Views/Sitemap.cshtml", CurrentPage);
}
public IPublishedContent FindContent(ActionExecutingContext actionExecutingContext)
{
IUmbracoContext context = _umbracoContextAccessor.GetRequiredUmbracoContext();
IPublishedContent? content = context.Content?.GetAtRoot().FirstOrDefault(r => r.ContentType.Alias == Homepage.ModelTypeAlias);
return content;
}
}
I do have these in a separate project to the main Umbraco install, so I’m thinking maybe the routes are being ignored? I can’t seem to route with typical MVC routing either. Any help is appreciated.