Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class SitemapController : RenderMvcController
public ActionResult SitemapXml()
var startNode = CurrentPage.Site();
if (startNode != null)
var sitemapService = new UmbracoSitemapService();
var items = sitemapService.GetItemsAsList(startNode.Id);
XNamespace xn = "";
var doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
var urlSet = new XElement(xn + "urlset");
urlSet.Add(new XAttribute("xmlns", ""));
foreach (var item in items)
urlSet.Add(new XElement(xn + "url", new XElement(xn + "loc", item.Url),
new XElement(xn + "lastmod", item.LastUpdateDate)));
return Content(String.Concat(doc.Declaration.ToString(), "\r\n", doc.ToString()), "text/xml");
return new HttpNotFoundResult("400");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.