【发布时间】:2019-10-24 17:40:40
【问题描述】:
在我的 .NET Core 2.2 网站中,我的 BlogController 中有一个控制器方法,它生成一个 sitemap.xml 文件:
public ActionResult SiteMap()
{
// logic here
return Content("<sitemap>...</sitemap>", "text/xml");
}
我设置了这条路线,以便站点地图将在https://mysite/sitemap 输出
routes.MapRoute(
name: "sitemap",
template: "sitemap",
defaults: new { controller = "Blog", action = "SiteMap" });
这行得通,因为访问 /sitemap 会导致 XML 内容被提供。
但是,当我访问 https://mysite/sitemap.xml 时,我收到 404 错误。
我很确定这与静态文件处理有关,但我不确定如何设置它以便/sitemap.xml 工作。
【问题讨论】:
-
如果您想访问
https://mysite/sitemap.xml,请确保sitemap.xml文件存在于wwwroot 文件夹中。 -
而
return Content只是生成一个xml文件显示在浏览器上,而不是上传到服务器。
标签: asp.net-core asp.net-mvc-routing asp.net-core-2.2