开发者

No xml output on page

开发者 https://www.devze.com 2022-12-29 00:05 出处:网络
I am trying to output xml on my asp开发者_Go百科x page. But it returns no result. The aspx page: <%@ Page Language=\"C#\" AutoEventWireup=\"false\" CodeBehind=\"Sitemap.aspx.cs\"

I am trying to output xml on my asp开发者_Go百科x 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消