0

ashx を使用して、Google のウェブサイト サイトマップを配信しています。最近まで、そのすべてが完全に機能していました。

http://www.naughtyfancydress.com/sitemap.ashxで Google でサイトマップをリクエストすると、次のようになります: XML 解析エラー: 整形式ではありません 場所: 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 されていたことです。

これにより、上で指定されていたとしても、明らかにコンテンツ エンコーディングが utf-8 から gzip に変更されます。サイトマップ ハンドラーがコンテンツを gzip として送信しないようにします。

于 2010-12-21T00:43:33.330 に答える