How to get the Sitefinity Sitemap Globalized

By default Sitefinity provides functionality to generate sitemap content for search engines. There is a solution to seperate the output in the sitemap for each implemented content language.

Sitefinity Sitemap

Onze technische blogs zijn in hetEngels. Dit doen wij omdat wij menen dat technische kennis van Sitecore en Sitefinity grensoverschrijdend moet zijn. Wij leren veel van buitenlandse developers, wij delen onze kennis ook graag met hen. Mochten er in de code fouten zitten of punten ter verbetering, dan gaan we graag het gesprek aan.

Sitemap content with custom code

For a specific project that contains multiple custom content, we ended up in serving sitemap content with custom code. This project uses multiple languages and in this particular case it is required to output only content for a given language

The customer in this matter has its localized websites registered as separate websites in Google Webmastertools ( ,,, etc.

In webmastertools, the sitemap for each locale website needs to be provided (, and each locale should output only the content of its own language.

This is how we solved this: In the webroot, we created a sitemap handler called “Sitemap.ashx” which is a HttpHandler.


public class SiteMap : IHttpHandler


private string langCode = String.Empty;

public void ProcessRequest(HttpContext context)


langCode = [ code to extract langCode from url, or extract from CultureInfo in current thread ]


string xmlData = this.CreateSitemapXml();



context.Response.ContentType = "text/xml";

context.Response.Charset = "UTF-8";





private string CreateSitemapXml()


XNamespace xmlNamespace = "";

XElement xmlRoot = new XElement(xmlNamespace + "urlset");


var pages = App.WorkWith().Pages()


.Where(page => page.ApprovalWorkflowState == "Published" && page.ShowInNavigation == true)



foreach (var page in pages)


CultureInfo culture = page.AvailableCultures.FirstOrDefault(ac => ac.ToString().Equals(langCode, StringComparison.OrdinalIgnoreCase));

string pageUrl = PageHelper.GetLanguageUrl(page.Id, culture);



new XElement(

xmlNamespace + "url",

new XElement(xmlNamespace + "loc", pageUrl),

new XElement(xmlNamespace + "lastmod", page.LastModified.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)),

new XElement(xmlNamespace + "changefreq", "daily"),

new XElement(xmlNamespace + "priority", "0.5")));


XDocument xmlDocument = new XDocument();



return "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" + xmlDocument.ToString();




This is a stripped down sample which outputs the page urls for the language given by the url. The PageHelper is a library to resolve the url from a page object. Now all we have to do is to set custom routing to lead url’s like to the sitemap.ashx.

In the Global.asax we need to add a route to the routetable:

RouteTable.Routes.Add("CustomSiteMapRouting", new Route("{country}/sitemap", new SiteMapRoutingHandler()));

And this SiteMapRoutingHandler is a custom RouteHandler which leads to the custom Sitemap handler:


public IHttpHandler GetHttpHandler(RequestContext requestContext)


return new SitefinityHandlers.SiteMap();



And then we are done here, will output only dutch content url’s.

Mind that for more obvious Sitemap functionality you should use the default Sitefinity functionality for generating a sitemap. The solution above can be used for similar requirements.