
You want to use OutputStream along with XmlWriter in your ASP.NET page. This will write XML directly into your page. This may be required for Google sitemaps or RSS feeds.
This C# tutorial shows how to use XmlWriter in an ASP.NET page. It uses the OutputStream property.
First, Response.OutputStream is a Stream object just like FileStream or many other versions in .NET. It can be written to in the same way. Response.End terminates the page. Response.End is called to stop any further content from being rendered. We pass OutputStream to the second method.
Response.WritePage that uses OutputStream [ASP.NET]
<%@ Page Language="C#" %>
<script runat="server" type="text/C#">
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";
WriteGoogleMap("http://www.dotnetperls.com/", Response.OutputStream);
Response.End();
}
</script>
Method that uses OutputStream [C#]
public void WriteGoogleMap(string urlBase, Stream stream)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
settings.Indent = true;
using (XmlWriter writer = XmlWriter.Create(stream, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
// Repeat this code:
writer.WriteStartElement("url");
writer.WriteElementString("loc", "[your url]");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
}
}Example using Google sitemap. Here we make a Google sitemap using some of the above methods and objects. The code replaces the entire .aspx markup stored in the file with the output of code that writes to the Response.

Description. It sets Response.ContentType to "text/xml". You need to do this for XML files like Google Sitemaps or RSS feeds. Internet Explorer can be difficult to deal with unless you do this right. Next, a method called WriteGoogleMap is called and is passed a string and a Stream object.
Second method. Here is the method that actually writes the XML to the Response.OutputStream. We construct an entire XML document from start to finish. Because the OutputStream is set as the buffer for XmlWriter, when XmlWriter adds elements they will be added to the Response. The XmlWriter writes to Stream. When we use the XmlWriter to write XML to the page, it is actually added directly to the aspx page.

We used OutputStream and XmlWriter to easily create dynamic XML files in aspx code-behind. It works very well and the XML you create will be interoperable and usable in every web browser and compliant program. The OutputStream property can be passed to a method that receives a formal parameter of Stream type.
XmlWriter Tutorial ASP.NET Tutorials