Long time developer, but not into SEO. I’ve been diving into sitemaps. I’m using ASP.NET Core Razor pages.

I have a route defined for server/Index/tag, where Index is my Index.cshtml file and a tag is just a parameter I am passing in from my database. I would like to create a sitemap.xml page that is autogenerated out of my database, seems logical.

However, when I try that, I get this autogenerated sitemap.xml page that has listed a bunch of the actual pages in my site, which is not what I want. It lists pages in the site but adds this:

<!--  created with Free Online Sitemap Generator www.xml-sitemaps.com  -->

Ok, so this seems to be something coming from Visual Studio 2022 (.NET 8). How the heck do I turn this thing off?

I’ve got a sitemap.cshtml file defined as:

@page "/sitemap.xml"
@model sitemapModel

@using Microsoft.AspNetCore.Http

    var server = "https://servername.com";
    Layout = null;
    Response.ContentType = "text/xml";
    await Response.WriteAsync("<?xml version='1.0' encoding='UTF-8' ?>");

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    @foreach (var tag in Model.Tags)

This page never seems to be called. If I go to /sitemap.xml, I get redirected to Index/sitemap.xml, which is not what I am looking for. What am I missing here? TIA.



I Put your exact code in my project, and everything works fine!
here is the image (just remove your tag from foreach and replace with for loop)
enter image description here

I’m suspecting that you build razor view instead of razor page empty.
so far with your explanations, your problem is from somewhere else.

let me know if it helped or not. if not, give us more info.