In this tutorial, you will learn how to build a sitemap.xml file within Umbraco 8. I'm assuming most people understand the benefits of sitemap XML. Introduced by Google in 2005, sitemap.xml ensures that all the content within your website is indexed correctly.

When it comes to building a sitemap.xml file within Umbraco almost all the online tutorials use a specific sitemap document-type when building a sitemap.xml. The downside of creating a sitemap document-type is:

  • A content editor accidentally deletes it
  • Sitemaps never change. Why make something that does not change configurable?

Assuming you are sold on the idea of creating a vanilla sitemap.xml then you will need to follow these steps:

  • Create an entry in the routing table
  • Create a view model and a controller
  • Create a view
  • Create a URL Rewrite Rule

The first thing that you will need to do is create an entry in the routing table to point to your vanilla MVC sitemap controller. In Umbraco V8 this will be done using a composer - [ee this article for more information

Next, let us create the view model - otherwise, the controller code below will not compile:

Next, let us create the controller:

As we are using an MVC controller, do not forget to register the controllers with the DI framework:

Lastly, you will need to create a view that will render out the items:

Enjoy!