I have an upload control that calls a handler from the client and is to send back a string of xml to the client. The code below works fine in chrome but is sending weird xml back to the client in IE.
Handler Code:
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
var uploadInfo = context.Request.Files[0];
var uploadStream = uploadInfo.InputStream;
var upload = new byte[uploadInfo.ContentLength];
uploadStream.Read(upload, 0, uploadInfo.ContentLength);
var payload = System.Text.Encoding.UTF8.GetString(upload);
XmlDocument doc = new XmlDocument();
doc.LoadXml(payload);
context.Response.ContentType = "application/xml";
context.Response.Write(doc.OuterXml);
//context.Response.Write(payload);
}
}
The XML string debugged from handler before sent to client (which looks correct)
<?xml version="1.0"?>
<ApplicationData>
<DataElement name="Comments" type="String"></DataElement>
<DataElement name="ModAuthor" type="String"></DataElement>
<DataElement name="CreateDate" type="Datetime"></DataElement>
<DataElement name="Author" type="String"></DataElement>
<DataElement name="StatusDate" type="Datetime"></DataElement>
<DataElement name="StatusDisp" type="String"></DataElement>
<DataElement name="Status" type="Number"></DataElement>
<DataElement name="Approved" type="Number"></DataElement>
<DataElement name="Submitted" type="Number"></DataElement>
<DataElement name="LogNumber" type="Number"></DataElement>
</ApplicationData>
Then XML string that is being sent back is:
<DIV class=e><SPAN class=b> </SPAN> <SPAN class=m><?</SPAN><SPAN class=pi>xml version="1.0" </SPAN><SPAN class=m>?></SPAN> </DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em" class=c><A class=b onfocus=h() onclick="return false" href="#">-</A> <SPAN class=m><</SPAN><SPAN class=t>ApplicationData</SPAN><SPAN class=m>></SPAN></DIV>
<DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Comments</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>String</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>ModAuthor</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>String</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>CreateDate</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Datetime</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Author</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>String</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>StatusDate</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Datetime</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>StatusDisp</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>String</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Status</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Number</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Approved</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Number</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b> </SPAN> <SPAN class=m><</SPAN><SPAN class=t>DataElement</SPAN> <SPAN class=t>name</SPAN><SPAN class=m>="</SPAN><B>Submitted</B><SPAN class=m>"</SPAN><SPAN class=t> type</SPAN><SPAN class=m>="</SPAN><B>Number</B><SPAN class=m>"</SPAN><SPAN class=m> /></SPAN> </DIV></DIV>
<DIV><SPAN class=b> </SPAN> <SPAN class=m></</SPAN><SPAN class=t>ApplicationData</SPAN><SPAN class=m>></SPAN></DIV></DIV></DIV>
For some reason from the XML is getting translated to the client in a totally different format.
I have a strange feeling that this has to do with encoding, I had a similar problem once with IE.
I see in your code that you use UTF-8 encoding to get the xml as string. Try to add the following header :
<?xml version="1.0" encoding="UTF-8"?>
to your XML file. I know that if you leave it out it is auto-detected, but try to do this and also try to open your file with something like Notepad++ and save in UTF-8 encoding. Also, if the file is generated pragmatically, check the code and try to force UTF-8 encoding.
In my experience with web applications, the place where IE screws up (most) is where there are some default values that are different from Chrome, Firefox, Opera, Safari, etc. If you do not explicitly enter these values, the browser will set it's defaults, but if you enter them in code, you will force a certain behaviour. This is not required for Chrome, Mozilla, etc. but will "fix" IE's interpretation.
One of the above mentioned default values is the encoding http://social.technet.microsoft.com/Forums/en-US/winserverGP/thread/2f5cdeff-3723-43bf-a880-d4a41222e24d/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With