ICodeFactory Labs

FCKEditor with ASP.NET - Fix “The server did not send back a proper XML response error”.

by Sergio 7. July 2009 10:47

I like FCKEditor. Our company is using it on several projects, and it mainly works fine, it has a number of different functionalities and it integrates well.

Recently we integrated FCKEditor with an asp.net 3.5 web application. We wanted to allow the client to update some contents on the web site and upload/manipulate images, but we faced a strange exception that stated:

The server didn’t send back a proper XML response. Please contact your system administrator.
XML request error: Ok (200)

 

xmlrequesterror_image1

Response text looked scrambled and messy.

Our first reaction was to search for the same bug on net, but after a few days I did not find anything barely useful!

That’s about when I realized I’ll have to investigate it by myself.

First of all I supposed I should blame some response mime type or format, so I dived into the FCKEditor project source code and found a class named XmlResponseHandler.

This class is used to clear the response object, set the content encoding and content type.

It all looked well. It was time to put some break points and investigate what is going on there.

I monitored two methods: SetupResponse and SendResponse.

private static void SetupResponse( HttpResponse response )

{

// Cleans the response buffer.

response.ClearHeaders();

response.Clear();

// Prevent the browser from caching the result.

response.CacheControl = "no-cache";

// Set the response format.

response.ContentEncoding = System.Text.UTF8Encoding.UTF8;

response.Charset = "utf-8";

response.ContentType = "text/xml";

}

public void SendResponse()

{

SetupResponse();

Response.Write( Xml.OuterXml );

Response.End();

}

Let’s put some break points and check what is going on while looking for the xml response from the server.

code_with_break_points_image2

My attention was drawn to data.

xmldata_image3

SendResponse method has a well formed xml. Let’s go further through the code.

Oops!

The server didn’t send back a proper XML response. Please contact your system administrator.

XML request error: Ok (200)

 

The same error again. Good. That means it is not about the data. Response looks like it is scrambled or packed when it comes to the client side!

That is a clue. Let’s investigate an interesting property of the Response object. It is the Filter property.

Response.Filter is a stream that is used to process data before it is sent to browsers, so if you, for example like to convert all cases to upper this is the place for your custom stream.

I investigated that property and found its value interesting.

deflatestream_image4

There was a DeflateStream object. This means response is compressed by server and sent to client as a compressed stream. This is why I got and strange encoded characters as error.

Fix was easy. I added one line of code:

Response.Filter = null;

private static void SetupResponse( HttpResponse response )

{

// Cleans the response buffer.

response.ClearHeaders();

response.Clear();

response.Filter = null;

// Prevent the browser from caching the result.

response.CacheControl = "no-cache";

// Set the response format.

response.ContentEncoding = System.Text.UTF8Encoding.UTF8;

response.Charset = "utf-8";

response.ContentType = "text/xml";

}

Build the solution and run it again. It works.

It was simple fix, but a very hard one to find. What is most amazing for me is that it was not found by other members of the community so far. I hope this article will help. Does it?

Currently rated 4.0 by 11 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

ASP.NET


Contact

Development and Sales
ICodeFactory d.o.o.
Trg Marije Trandafil 24/2
21000 Novi Sad
Serbia, Europe
Phone: +381 (0)21 41 77 08
info[at]icodefactory[dot]com

Headquarter
T.C. Bagljaš, Lok. 11
23000 Zrenjanin
Serbia, Europe

Working hours
Monday - Friday
8am - 4pm (GMT+1)