Skip to content

Instantly share code, notes, and snippets.

@sitefinitySDK
Created June 17, 2020 17:26
Show Gist options
  • Save sitefinitySDK/c8a8fb7c63d1a148510e924ee08a1734 to your computer and use it in GitHub Desktop.
Save sitefinitySDK/c8a8fb7c63d1a148510e924ee08a1734 to your computer and use it in GitHub Desktop.
SF_13.0, SF_13.1, SF_13.2, SF_13.3, SF_14.0, SF_14.1, SF_14.2, SF_14.3 - https://www.progress.com/documentation/sitefinity-cms/add-a-custom-url-to-the-sitemap
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)
{
// gets the entries that are about to be written in the sitemap
var entries = evt.Entries.ToList();
// creates a new sitemap entry
SitemapEntry newSitemapEntry = new SitemapEntry();
//sets the location property of the new sitemap entry
newSitemapEntry.Location = "http://<site domain>/my-custom-entry";
newSitemapEntry.Priority = 1;
// adds the new sitemap entry to the collection of the entries
entries.Add(newSitemapEntry);
// sets the collection of entries to the modified collection
evt.Entries = entries;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment