Skip to content

Instantly share code, notes, and snippets.

@jordanwallwork
jordanwallwork / SitemapGenerator.cs
Created August 18, 2016 11:37
dotnet core mvc sitemap generator
// Modified code from http://dotnetthoughts.net/generate-dynamic-xml-sitemaps-in-aspnet5/
public static class SitemapGenerator
{
private static string _sitemapContent = null;
public static string Generate(string rootUrl, IUrlHelper urlHelper)
{
if (_sitemapContent == null) // I only wanted to generate this once and then stash the result. Caching the action that calls this would probably be better
{
string sitemapContent = "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">";