views:

31

answers:

1

I am trying to output xml on my aspx page. But it returns no result.

The aspx page:

<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Sitemap.aspx.cs"
 Inherits="Servicebyen.Presentation.Web.Sitemap" %>

The code behinde:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Clear();
    Response.ContentType = "text/xml";

    var writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);

    writer.Settings.CloseOutput = false;
    writer.WriteStartDocument();
    writer.WriteStartElement("urlset");
    writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
    writer.WriteEndElement();
    writer.WriteEndDocument();
    writer.Flush();
    writer.Close();
    Response.End();
}

Can you see anything wrong with this?

A: 

If you are testing this out in Google Chrome then you will get a blank page is it doesn't render xml files well from websites.

Another thing to try is rather than implement this as a page implement it as a Generic Handler. This avoids the overhead of the Page Lifecycle for ASP.NET and reduces the places where errors can occur or mistakes can be made.

Matthew Steeples