0

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.

asn1981
  • 237
  • 1
  • 7
  • 20
  • When I go to the URL: http://www.naughtyfancydress.com/sitemap.ashx, I get nothing as response, maybe that is the issue. Did you browse the URL and verified that you are getting XML output indeed? – Chandu Dec 19 '10 at 15:21
  • Well if you browse in chrome you do get nothing, but I think thats a chrome issue. If you try in IE or Firefox you get the error I mentioned above which is: XML Parsing Error: not well-formed Location: http://naughtyfancydress.com/sitemap.ashx Line Number 1, Column 1:`I�%&/m�{J� – asn1981 Dec 19 '10 at 15:24
  • After further investigation the exact code above works in my .net 3.5 project. It's only stopped working on the new website written in .net 4. I think it is related to this, but what to do to fix the issue? – asn1981 Dec 21 '10 at 00:35

1 Answers1

0

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.

asn1981
  • 237
  • 1
  • 7
  • 20