ASP.Net C#MVC5 Razor查看XML站点地图
发布时间:2020-12-16 07:19:59 所属栏目:asp.Net 来源:网络整理
导读:我的控制器动作看起来像这样. public ActionResult Sitemap() { Response.ContentType = "application/xml"; return View(); } 我的视图Sitemap.cshtml看起来像这样. @{Layout = null;}?xml version='1.0' encoding='UTF-8' ?urlset xmlns="http://www.googl
我的控制器动作看起来像这样.
public ActionResult Sitemap() { Response.ContentType = "application/xml"; return View(); } 我的视图Sitemap.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> 我在浏览器中获取ERROR页面(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> 它似乎是在标头之前发送空的空格或行,导致上述错误. 页面源输出 ----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# sitemaps.xml in asp.net mvc ASP.NET Web.sitemap to Generate sitemap.xml 解决方法
我通过在Response.Write中添加XML标记来解决问题
@{ Response.Write("<?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> 感谢EvanSwd (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 为什么Visual Studio会拒绝访问,尝试使用NuGet软
- asp.net-ajax – ScriptManager.RegisterClientScriptInclu
- asp.net – 从SignalR中的所有组中删除连接
- asp.net-mvc-3 – 默认路由不起作用
- asp.net signalR 专题—— 第三篇 如何从外部线程访问 Pers
- asp.net-mvc-3 – ASP.NET MVC3 WebGrid – 自定义,服务器端
- asp.net – HMACSHA1.ComputeHash()线程安全问题
- asp.net-mvc – MVC3自定义格式化日期的不显眼日期验证
- asp.net-mvc – 没有区域的ASP.NET Web API中的多级路由
- asp.net – 如何在web.config中设置text / html的默认内容类
推荐文章
站长推荐
- ASP.NET(C#)应用程序配置文件app.config/web.con
- asp.net – 将可以为空的int绑定到asp:TextBox
- asp.net – 我如何验证日期?
- 无法找到asp.net-mvc – System.Data.Entity.Dat
- asp.net-mvc – ASP.Net MVC 3.0 Ajax.ActionLin
- asp.net-mvc-4 – Razor模板编辑器不喜欢我的Kno
- asp.net-mvc-3 – 重定向与RedirectToRouteResul
- asp.net-mvc – ASP.NET MVC – Partial View可以
- asp.net-mvc – 控制器中的模拟服务器
- asp.net-mvc – 在Asp MVC Telerik网格和实体框架
热点阅读