我正在使用 ashx 为 Google 提供我的网站站点地图。直到我最近,它都运行良好。
在http://www.naughtyfancydress.com/sitemap.ashx在 Google 中请求站点地图时,我得到:XML Parsing Error: not well-formed Location: http://naughtyfancydress.com/sitemap.ashx 第 1 行,第 1 列:`I�%&/m�{J�</p>
我在 ashx 中的精简代码如下所示:
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(3600));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
var writer = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("urlset");
writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xsi:schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd");
writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
writer.WriteStartElement("url");
writer.WriteElementString("loc", "http://www.naughtyfancydress.com/");
writer.WriteElementString("changefreq", "daily");
writer.WriteElementString("priority", "1.0");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
欢迎任何关于如何解决的想法。
编辑:如果您在 Chrome 中检查上面的链接,则不会显示任何内容,我认为这是 Chrome 问题,请使用 FireFox 检查链接。