ASP.NET MVC Sitemap.xml错误
我有一个有效的sitemap.xml文件。当我尝试将此文件作为sitemap.xml提供时,问题就出现了。我得到以下错误:ASP.NET MVC Sitemap.xml错误,asp.net,xml,asp.net-mvc-4,sitemap,nopcommerce,Asp.net,Xml,Asp.net Mvc 4,Sitemap,Nopcommerce,我有一个有效的sitemap.xml文件。当我尝试将此文件作为sitemap.xml提供时,问题就出现了。我得到以下错误: This page contains the following errors: error on line 1 at column 95: Extra content at the end of the document Below is a rendering of the page up to the first error. 当我从浏览器中检查/sitemap.
This page contains the following errors:
error on line 1 at column 95: Extra content at the end of the document
Below is a rendering of the page up to the first error.
当我从浏览器中检查/sitemap.xml时,每个元素标记都会将其添加到其中
<url xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
the rest
</url>
下面是我拥有并试图返回的文件的示例
<?xml version="1.0" encoding="utf-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>LINK</loc>
</url>
THE REST OF URLS
</urlset>
链接
其余的URL
我曾尝试将“application/xml”切换为“text/xml”,但没有解决这个问题。我是否没有正确使用XmlDocument,或者我是否没有完全理解return Content()会发生什么
感谢您的帮助
谢谢最后解决的问题这是一个简单的解决方案
XmlDocument xml = new XmlDocument();
xml.Load(@"C:\sitemap.xml");
return Content(xml.DocumentElement.InnerXml, "application/xml");
改为
XmlDocument xml = new XmlDocument();
xml.Load(@"C:\sitemap.xml");
return Content(xml.DocumentElement.OuterXml, "application/xml");
希望这对以后有帮助
XmlDocument xml = new XmlDocument();
xml.Load(@"C:\sitemap.xml");
return Content(xml.DocumentElement.OuterXml, "application/xml");