質問

ASHXを使用して、Google用のWebサイトサイトマップを配信しています。最近まで完璧に機能しました。

Googleでサイトマップをリクエストするとき http://www.naughtyfancydress.com/sitemap.ashx 私は得ます:XML解析エラー:よく形成されていない場所: http://naughtyfancydress.com/sitemap.ashx行番号1、列1: `i�%&/m�{j�

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でリンクを確認してください。

役に立ちましたか?

解決

他の誰にとっても、問題はGlobal.asaxで、Application_prererequesthandLerexecuteメソッドでは、私のコンテンツでgzip'sであったことでした。

これにより、上記で指定されていても、UTF-8からGZIPにエンコードするコンテンツが明らかに変更されます。これが修正です。SiteMapハンドラーがGZIPとしてコンテンツを送信しないことを確認してください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top