KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have encountered many half-solutions to the task of returning XML in ASP.NET. I don't want to blindly copy & paste some code that happens to work most of the time, though; I want the right code, and I want to know why it's right. I want criticism; I want information; I want knowledge; I want understanding. Below are code fragments, in order of increasing complexity, representing some of the partial solutions I've seen, including some of the further questions each one causes, and which I'd like to have answered here. A thorough answer must address why we must have or must not have any of the following things, or else explain why it's irrelevant. Response.Clear(); Response.ContentType = "text/xml"; Response.ContentEncoding = Encoding.UTF8; Response.ContentEncoding = Encoding.UTF16; Response.ContentType = "text/xml; charset=utf-8"; Response.ContentType = "text/xml; charset=utf-16"; Response.End() Using an aspx with the front-file guts ripped out Using an ashx file In the end, imagine you need to write the contents of a helper function like this: ///<summary>Use this call inside your (Page_Xxx) method to write the ///xml to the web client. </summary> ///<remarks>See for https://stackoverflow.com/questions/543319/how-to-return-xml-in-asp-net ///for proper usage.</remarks> public static void ReturnXmlDocumentToWebClient( XmlDocument document, Page page) { ... } Every solution I see starts with taking an empty aspx page, and trimming all the HTML out of the front file (which causes warnings in Visual Studio): <%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetTheXml.aspx.cs" Inherits="GetTheXml" %> Next we use the Page_Load ev
Tags (comma-separated)
Save Edits
Cancel