Blog / Generate your sitemap from the database, not by hand

Generate your sitemap from the database, not by hand

A hand-maintained sitemap.xml is drift waiting to happen. Generate it from the same database the site renders from, and it can't fall out of sync — because it is the content.

Published

June 2026

Length

1 min read

Topics

SEO · Architecture · ASP.NET

A hand-maintained sitemap.xml is drift waiting to happen. You publish an article, you forget the sitemap, and search engines never learn the page exists. The file and the reality it's meant to describe diverge in the first week, and nobody notices, because nothing errors.

The fix is to stop maintaining it and start deriving it. Generate the sitemap from the same database the site renders from: every published item in, every draft out, automatically. It can't fall out of sync with your content because it is your content, queried at request time. Publish a post and it's in the sitemap; unpublish it and it's gone — no second step to forget.

The same logic applies to robots.txt: emit it from code so the disallow rules and the sitemap URL ship with the application instead of living in a static file someone has to remember to update.

The principle outlasts the specific files: any artifact whose job is to mirror your content should be derived from that content, not maintained beside it. Two copies of the truth is one copy too many.