How to return XML in ASP.NET?

前端 未结 9 1461
粉色の甜心
粉色の甜心 2020-11-28 20:17

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, th

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 20:39

    XmlDocument xd = new XmlDocument();
    xd.LoadXml(xmlContent);
    
    context.Response.Clear();
    context.Response.ContentType = "text/xml";
    context.Response.ContentEncoding = System.Text.Encoding.UTF8;
    xd.Save(context.Response.Output);
    context.Response.Flush();
    context.Response.SuppressContent = true;
    context.ApplicationInstance.CompleteRequest();
    

提交回复
热议问题