Sitemap xml for second site
Closed this issue · 7 comments
Hi
I have main web site /
and second site /secondsite
. I don't know how to get sitemap data for second site.
For main site I can use /api/sitemap
as site map but it does not contain data for second site.
I tried /secondsite/api/sitemap
but I got page not found.
So I think /api/sitemap
should return data for whole domain or there should be link to get sitemap for second site only. I'm not sure what is correct from your point of view.
If you are using cloudscribe multi tenancy by host name then the sitemap url will be hostname/api/sitemap
if you want a site map that aggregates multiple sub domains you could create a sitemap index xml file that lists all the different sitemaps. I have no plan to automatically aggregate sitemaps from different tenants.
If you are using cloudscribe folder multi-tenancy then the site map url for the root site will be /api/sitemap and the sitemap for folder tenants should be /folder/api/sitemap
However, I just tested this and it is not working for folder tenants. So there is a bug there. Looking at the documentation it seems that controllers and actions that use attribute routing cannot be reached by conventional routes (which may not have been true back in 1.x versions of aspnet core) so we can't add an additional route with the site folder constraint using conventional routing. Also since the navigation and sitemap are loosely coupled and have no direct dependency on cloudscribe core, we can't really bake in a route constraint that is specific to cloudscribe core.
This "could" be solved by removing the attribute route and making everyone use conventional routes for the sitemap controller, but that would be a breaking change I would rather avoid.
The option I can think of to try are make the SiteMapController Index action virtual and try to sub class the controller for use in cloudscribe Core folder tenants.
Hi Joe. I'm using folder folder multi-tenancy. And I also found the same problem for /api/metaweblog. It also uses attribute routing. And I actually put my blog on second site. Perhaps there is something else as well that uses attribute routing.
I actually found this: https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/application-model?view=aspnetcore-2.1and it is allow to override routing (I did search by: Using "Application Model" to customize attribute routes). Perhaps it will help
I got your fix and got a crash:
NullReferenceException: Object reference not set to an instance of an object. cloudscribe.Web.SiteMap.NavigationTreeSiteMapNodeService.ResolveUrl(NavigationNode node, IUrlHelper urlHelper) cloudscribe.Web.SiteMap.NavigationTreeSiteMapNodeService.GetSiteMapNodes(CancellationToken cancellationToken) cloudscribe.Web.SiteMap.Controllers.SiteMapController.Index() cloudscribe.Core.Web.Controllers.FolderSiteMapController.Index()
I'm still working on the problem. Will let you know when the solution is ready.
Ok, it took while to solve it but if you update to all the latest cloudscribe nugets and you add these routes in the if(useFolders) section of RoutingAndMvc.cs it should work.
I solved also /folder/api/rss and folder/api/metaweblog
routes.MapRoute(
name: "apifoldersitemap",
template: "{sitefolder}/api/sitemap"
, defaults: new { controller = "FolderSiteMap", action = "Index" }
, constraints: new { name = new cloudscribe.Core.Web.Components.SiteFolderRouteConstraint() }
);
routes.MapRoute(
name: "apifoldermetaweblog",
template: "{sitefolder}/api/metaweblog"
, defaults: new { controller = "FolderMetaweblog", action = "Index" }
, constraints: new { name = new cloudscribe.Core.Web.Components.SiteFolderRouteConstraint() }
);
routes.MapRoute(
name: "apifolderrss",
template: "{sitefolder}/api/rss"
, defaults: new { controller = "FolderRss", action = "Index" }
, constraints: new { name = new cloudscribe.Core.Web.Components.SiteFolderRouteConstraint() }
);
I've also updated the project template again to include these routes.
Also in the .csproj of your web app you should remove this:
<PackageReference Include="cloudscribe.Syndication.Web" Version="2.0.*" />
because it is not the new version and it will come in as a transitive dependency from cloudscribe.SimpleContent.Syndication
Hi Joe.
I updated template, recreated project from template and synched changeы. Checked sitemap and metaweblog and everything works great! Thank you again for your help!
@cheverdyukv many thanks for reporting this bug! I'm glad to have that fixed. I'm sure it was working a while back but maybe it broke during the change from aspnetcore 1.x to 2.x