You can generate a Sitemap automatically at /Sitefinity/Administration/sitemap/sitemap
So there's two links on that page
The .gz you can't view in browser, and the xml just points at the gz
So WHY would we want to view the Sitemap you're probably thinking. There's a couple reasons, but the primary being you need to be able to audit that someone hasn't forgotten to remove a page from indexing, or maybe you have a dynamic content widget that's generating bad routes because it's not in "Master" mode.
So we're just going to take Sitefinity's documentation example and expand on it a bit.
We're going to make sure there's no trailing slashes in the output, it seems to do that to the homepage at least. Also remove localhost, because why not... Then finally we're going to just loop through all the pages and dump them to a ~/sitemap.txt file you can access in your browser!
Sitemap_Urls_Global.asax.csView on GitHub using System;
using System.Linq;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.SitemapGenerator.Abstractions.Events;
using Telerik.Sitefinity.SitemapGenerator.Data;
namespace SitefinityWebApp
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(this.Bootstrapper_Initialized);
}
void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
{
if (e.CommandName == "Bootstrapped")
{
EventHub.Subscribe<ISitemapGeneratorBeforeWriting>(Before_Writing);
}
}
private void Before_Writing(ISitemapGeneratorBeforeWriting evt)
{
var currentContext = Telerik.Sitefinity.Services.SystemManager.CurrentHttpContext;
var host = currentContext.Request.Url.Host;
//Strip out trailing slashes and remove localhost
foreach (var e in evt.Entries)
{
e.Location = e.Location.TrimEnd('/').Replace("http://localhost", $"https://{host}");
}
//Dump to readable sitemap file
//https://developers.google.com/search/docs/advanced/sitemaps/build-sitemap#expandable-3
try
{
string flatSitemap = "";
foreach (var e in evt.Entries.OrderBy(x => x.Location))
{
flatSitemap += $"{e.Location}\n";
}
File.WriteAllText(currentContext.Server.MapPath("~/sitemap.txt"), flatSitemap);
}
catch (Exception ex)
{
//Handle error?
}
}
}
}