문제

I'm using a ashx to deliver my websites sitemap for Google. Its all worked perfectly until I recently.

When requesting the sitemap in Google at http://www.naughtyfancydress.com/sitemap.ashx I get: XML Parsing Error: not well-formed Location: http://naughtyfancydress.com/sitemap.ashx Line Number 1, Column 1:`I�%&/m�{J�

My stripped down code in the ashx looks like:

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();

Any ideas on how to resolve would be welcomed.

EDIT: If you check the link above in Chrome nothing will display, I believe this is a Chrome issue, please check the link with FireFox.

도움이 되었습니까?

해결책

For anyone else, the issue was that in the Global.asax, in the Application_PreRequestHandlerExecute method I was gzip'in my content.

This obviously changes the content encoding to gzip from utf-8 even though it was specified above. That's the fix, ensure the sitemap handler doesn't send content as gzip.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top