开发者

ASP.NET MVC Google Sitemap from ContentResult - Incorrect namespace

开发者 https://www.devze.com 2022-12-20 01:22 出处:网络
I created a sitemap generated by a ContentResult however Google keeps telling me my namespace is incorrect. Any ideas?

I created a sitemap generated by a ContentResult however Google keeps telling me my namespace is incorrect. Any ideas?

My Code:

public ContentResult Index()
    {
        //Build RSS for sitemap
        XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
        const string url = "http://www.openarmssoberliving.com/{0}";
        var encoding = Response.ContentEncoding.WebName;
        var items = _pagesRepos.Pages.OrderBy(p => p.Id).ToList();
        items.Add(new Page { Title = "Contact Us", Slug = "ContactUs", LastModified = items[0].LastModified });
        var sitemap = new XDocument(new XDeclaration("1.0", encoding, null),
            new XElement(ns + "urlset",
                f开发者_C百科rom item in items
                select
                new XElement(ns + "url",
                    new XElement(ns + "loc", string.Format(url, (item.Id != 1) ? item.Slug : "")),
                    new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", item.LastModified)),
                    new XElement(ns + "changefreq", "monthly"),
                    new XElement(ns + "priority", "0.5")
                  )
                )
              );
        return Content("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + sitemap, "text/xml");
    }

Output: http://www.openarmssoberliving.com/Sitemap

Error: Line 2. Your Sitemap or Sitemap index file doesn't properly declare the namespace.


It seems like goole now likes my feed. Original code works.

0

精彩评论

暂无评论...
验证码 换一张
取 消