아마도이 최선의 방법은 HttpHandler/ASHX 파일을 사용하는 것일 수 있습니다. 그러나 페이지로 처리하고 싶다면 완벽하게 가능합니다. 두 가지 핵심 사항은 다음과 같습니다.
- 빈 페이지를 사용하십시오. ASPX의 마크 업에서 원하는 것은 모두 < % Page ... %> 지시어입니다.
- 는 XML로 응답 스트림 의 ContentType을 설정 - 당신이 자체가 당신에게 달려 XML을 생성하지만, XML 객체 그래프를 나타내는 경우, 당신은
System.Xml.Serialization
에서 XmlSerializer
을 (사용할 수있는 방법 Response.ContentType = "text/xml"
네임 스페이스)를 사용하여 XML을 직접 응답 스트림에 작성합니다. 이미 XML이있는 경우이의 ContentType을 설정 한 후
using System.Xml.Serialization;
// New up a serialiser, passing in the System.Type we want to serialize
XmlSerializer serializer = new XmlSerializer(typeof(MyObject));
// Set the ContentType
Response.ContentType = "text/xml";
// Serialise the object to XML and pass it to the Response stream
// to be returned to the client
serialzer.Serialize(Response.Output, MyObject);
후, 당신은 응답 스트림에 기입 한 후 종료하고 스트림을 플러시해야합니다.
// Set the ContentType
Response.ContentType = "text/xml";
Response.Write(myXmlString);
Response.Flush();
Response.End();
가능한 중복 : http://stackoverflow.com/questions/2295892/how-can-i-output-xml-from-code-behind-in-an-aspx-file – RemarkLima