In my .NET Core 2.2 website, I have a controller method within my BlogController
that generates a sitemap.xml file:
public ActionResult SiteMap()
{
// logic here
return Content("<sitemap>...</sitemap>", "text/xml");
}
I have this route set up so that the sitemap will be output at https://mysite/sitemap
routes.MapRoute(
name: "sitemap",
template: "sitemap",
defaults: new { controller = "Blog", action = "SiteMap" });
That works, in that accessing /sitemap
results in the XML content being served up.
However, when I access https://mysite/sitemap.xml
, I get a 404 error.
I'm pretty sure this is something to do with static file handling, but I'm not sure how to set it up so that /sitemap.xml
works.