0

我正在使用 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 检查链接。

4

1 回答 1

0

对于其他人来说,问题是在 Global.asax 中,在 Application_PreRequestHandlerExecute 方法中,我的内容是 gzip'in。

这显然会将内容编码从 utf-8 更改为 gzip,即使它已在上面指定。这就是修复,确保站点地图处理程序不会将内容作为 gzip 发送。

于 2010-12-21T00:43:33.330 回答