在创建的网站上生成站点地图​​使用WebMatrix+Razor

在创建的网站上生成站点地图​​使用WebMatrix+Razor,razor,sitemap,webmatrix,auto-generate,Razor,Sitemap,Webmatrix,Auto Generate,我需要生成一个网站地图,以验证与谷歌网站管理员工具的网站 如何为我的网站自动生成站点地图?我认为这是您最好的选择: 阅读以下页面: 请尝试以下示例: @using System.Xml.Linq; @{ var urls = new List<string>{"home", "about", "contact"}; XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; var baseur

我需要生成一个网站地图,以验证与谷歌网站管理员工具的网站


如何为我的网站自动生成站点地图?

我认为这是您最好的选择:

阅读以下页面:

请尝试以下示例:

@using System.Xml.Linq;
@{
    var urls = new List<string>{"home", "about", "contact"};
    XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
    var baseurl = "http://www.domain.com/{0}";
    var sitemap = new XDocument(
        new XDeclaration("1.0", "utf-8", "yes"),
            new XElement(ns + "urlset",
                from url in urls select
                new XElement("url",
                    new XElement("loc", string.Format(baseurl, url)),
                    new XElement("lastmod", String.Format("{0:yyyy-MM-dd}", DateTime.Now)),
                    new XElement("changefreq", "monthly"),
                    new XElement("priority", "0.5")
                    )
                )
            );
    Response.ContentType = "text/xml";
    sitemap.Save(Response.Output);
}

将文件另存为Sitemap.cshtml。显然,您需要将列表替换为地图的位置源。但至少您可以看到XML是如何生成的。

该网站是在WebMatrix中开发的。。有了Razor,作为MVC的提供者能帮上忙吗?“我不明白。”里德曼:没问题。只需注册提供者,就可以开始使用它了。文档就在CodePlex项目的主页上。谢谢。。。它甚至是需要的!