2010-12-19 10 views
0

私はashxを使用してGoogleのWebサイトマップマップを配信しています。最近まで、そのすべてが完璧に機能していました。C#Ashx Google XMLのサイトマップ生成エラー

http://www.naughtyfancydress.com/sitemap.ashxでグーグルでサイトマップを要求する場合、私は得る:解析エラー XML:ない整形 場所:http://naughtyfancydress.com/sitemap.ashx 行番号1、列1: `I%&/M {J

を解決する方法上の任意のアイデアは歓迎されるだろう

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

ASHXで私のストリップダウンのコードは次のようになります。

編集:Chromeの上記のリンクを確認しても何も表示されませんが、これはChromeの問題だと思うので、FireFoxのリンクを確認してください。

+0

URL:http://www.naughtyfancydress.com/sitemap.ashxにアクセスすると、私は何も応答しません。多分それが問題です。 URLを参照して、実際にXML出力を取得していることを確認しましたか? – Chandu

+0

あなたがクロムをブラウズすれば、何も得られませんが、クロムの問題だと思います。あなたがIEやFirefoxで試してみると、上で述べたエラーが発生します:XML構文解析エラー:整形式でない場所:http://naughtyfancydress.com/sitemap.ashx行番号1、列1: 'I%%& /m {J – asn1981

+0

詳しい調査の後、上記の正確なコードは、私の.net 3.5プロジェクトで動作します。それは、ネット4で書かれた新しいウェブサイトの作業を停止しただけです。私はそれがこれに関連していると思いますが、問題を解決するために何をすべきですか? – asn1981

答えて

0

他の人にとっては、Global.asaxでは、Application_PreRequestHandlerExecuteメソッドで私は自分のコンテンツをgzipしていました。

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

関連する問題