【问题标题】:Generate sitemap on a website made ​​with WebMatrix + Razor在使用 WebMatrix + Razor 制作的网站上生成站点地图
【发布时间】:2011-05-13 03:03:20
【问题描述】:

我需要生成站点地图以使用 Google 网站管理员工具验证网站。

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

【问题讨论】:

    标签: razor sitemap webmatrix auto-generate


    【解决方案1】:

    试试这个示例:

    @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 是如何生成的。

    【讨论】:

    • 谢谢...它甚至是需要的!
    【解决方案2】:

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

    ASP.NET MVC SiteMap provider

    阅读这些页面:

    Dynamic sitemaps

    Exporting the sitemap for search engine indexing

    【讨论】:

    • 该站点是在WebMatrix .. 中使用Razor 开发的,作为MVC 的提供者可以提供帮助吗?我不明白。
    • @Riderman:没问题。只需注册提供程序,您就可以开始使用它。文档就在 CodePlex 项目的主页中。
    猜你喜欢
    • 1970-01-01
    • 2017-11-29
    • 2020-05-22
    • 2010-11-09
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 2011-03-29
    • 2015-08-11
    相关资源
    最近更新 更多