My Controller Action выглядит так.ASP.Net C# MVC5 Razor View XML sitemap
public ActionResult Sitemap()
{
Response.ContentType = "application/xml";
return View();
}
My View Карта сайта.cshtml выглядит следующим образом.
@{Layout = null;}<?xml version='1.0' encoding='UTF-8' ?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
<url>
<loc>https://www.mywebsitename.com/home</loc>
<lastmod>2006-12-12</lastmod>
<changefreq>weekly</changefreq>
<priority>1.00</priority>
</url>
</urlset>
Я получаю следующее сообщение об ошибке в браузере для страницы (http://localhost:50831/Sitemap
)
This page contains the following errors:
error on line 2 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.
Я удалили все пробелы из View (Sitemap.cshtml). но все же ошибка
Я даже попробовал this и обратный порядок, как показано ниже, но все еще ошибка.
<?xml version='1.0' encoding='UTF-8' ?>
@{ Layout = null;}
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
<url>
<loc>https://www.mywebsitename.com/home</loc>
<lastmod>2006-12-12</lastmod>
<changefreq>weekly</changefreq>
<priority>1.00</priority>
</url>
</urlset>
Похоже, что он отправляет пустое пространство или строку перед заголовком, что вызывает ошибку выше. Макет равен null, представление начинается с тэга xml и откуда он получает пустое пространство.
выход источника страницы
----EMPTY LINE----
<?xml version='1.0' encoding='UTF-8' ?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
<url>
<loc>https://www.mywebsitename.com/home</loc>
<lastmod>2006-12-12</lastmod>
<changefreq>weekly</changefreq>
<priority>1.00</priority>
</url>
</urlset>
Я не мог получить мою голову вокруг, почему? Есть идеи?
Я проверил следующее, но все еще не мог в состоянии найти ответ
How to create XML sitemap programmatically in c#
ASP.NET Web.sitemap to Generate sitemap.xml
Как выглядит фактический вывод, который вы получаете? – Svish
@Svish с исходным кодом – Developer