Why doesn't IE recognize my output as XML?

I built the following code for XML output:

public static XDocument Serialize<T>(this T source) where T : class { XDocument document = new XDocument(); XmlReflectionImporter xmlReflection = new XmlReflectionImporter(); XmlTypeMapping xmlMapping = xmlReflection.ImportTypeMapping(typeof(T)); XmlSerializer xmlSerializer = new XmlSerializer(xmlMapping); using (XmlWriter xmlWriter = document.CreateWriter()) xmlSerializer.Serialize(xmlWriter, source); return document; } 

Then on one of my aspx pages, I have the following output:

  XDocument output = GetSomeXmlSerializedOutput(); output.Save(Response.OutputStream); 


GetSomeXmlSerializedOutput() is basically derived from serving the class to the Serialize extension method.

The page title is as follows:

 <%@ Page Language="C#" CodeBehind="Alerts.aspx.cs" Inherits="Infinix.Diageo.WebApp.Get.Alerts" ContentType="text/xml" %> 

Firefox correctly assumes only from ContentType that the output is XML. IE does not. XML output for reference:

 <?xml version="1.0" encoding="utf-8"?> <ALERTS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ALERT> <ID>1</ID> <TYPE>ALERT</TYPE> <NAME>neim</NAME> <DETAIL>diteil</DETAIL> <DATE>11/28/2010</DATE> <TIME>13:50:02</TIME> </ALERT> <ALERT> <ID>2</ID> <TYPE>EVENT</TYPE> <NAME>iven</NAME> <DETAIL>ditel</DETAIL> <DATE>11/28/2010</DATE> <TIME>13:50:15</TIME> </ALERT> <ALERT> <ID>3</ID> <TYPE>BIRTHDAY</TYPE> <NAME>pijazo</NAME> <DETAIL>grande!</DETAIL> <DATE>11/28/2010</DATE> <TIME>13:50:23</TIME> </ALERT> </ALERTS> 

Why doesn't IE recognize this output as genuine XML?

+4
source share
1 answer

Your page directive should set ContentType="application/xml" .

 <%@ Page Language="C#" CodeBehind="Alerts.aspx.cs" Inherits="Infinix.Diageo.WebApp.Get.Alerts" ContentType="application/xml" %> 
+3
source

All Articles