1

我正在使用以下代码从文件中获取 xml ..

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

                context.Response.ContentType = "text/plain";
                context.Response.Write(payload);

xml 看起来像这样,因为这一点正如预期的那样..

<?xml version="1.0"?>  
 <AData>
 <DataElement name="Comments" type="String"></DataElement> 
 <DataElement name="ModAuthor" type="String"></DataElement>  
 <DataElement name="CreateDate" type="Datetime"></DataElement>    
 <DataElement name="Author" type="String"></DataElement>   
 </AData>

我用这段代码调用我的处理程序..

  $.ajaxFileUpload({

                url: 'AjaxFileUploader.ashx',
                secureuri: false,
                fileElementId: 'fileToUpload',
                dataType: 'text',
                success: function (data, status) {

                    alert(data);

                },

                error: function (data, status, e) {
                    alert(e);
                }

            }

在 chrome 中一切都很好,但在 IE 中测试成功方法返回以下内容..

<DIV class=e><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;?</SPAN><SPAN class=pi>xml version="1.0" </SPAN><SPAN class=m>?&gt;</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>&lt;</SPAN><SPAN class=t>AData</SPAN><SPAN class=m>&gt;</SPAN></DIV>
<DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;</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> /&gt;</SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;</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> /&gt;</SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;</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> /&gt;</SPAN> </DIV></DIV>
<DIV class=e>
<DIV style="TEXT-INDENT: -2em; MARGIN-LEFT: 1em"><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;</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> /&gt;</SPAN> </DIV></DIV>
<DIV><SPAN class=b>&nbsp;</SPAN> <SPAN class=m>&lt;/</SPAN><SPAN class=t>AData</SPAN><SPAN class=m>&gt;</SPAN></DIV></DIV></DIV>

有什么想法可以简单地返回从处理程序代码中获得的 xml 字符串?它在 chrome 中返回 xml,但 IE 自动为我提供了看起来是 html 和样式的内容。

4

1 回答 1

0

尝试添加X-Content-Type-Options: nosniff标题:http:
//blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx

context.Response.ContentType = "text/plain";
context.Response.AppendHeader("X-Content-Type-Options", "nosniff");
于 2013-03-14T14:21:21.233 回答