-
using System;
-
using System.Web;
-
using System.Xml;
-
using System.Xml.Linq;
-
namespace WebApplication1
-
{
-
public class RssHttpHandler : IHttpHandler
-
{
-
public void ProcessRequest(HttpContext context)
-
{
-
context.Response.ContentType = "text/xml";
-
context.Response.Write("<?xml version="1.0" encoding="UTF-8" ?>");
-
XElement rssFeed = new XElement("rss",new XAttribute("version","2.0"));
-
string fixedUrl = "http://www.freeflying.com/article";
-
string wholeUrl = string.Empty;
-
XElement channel = new XElement("channel",
-
new XElement("title","freeflying"),
-
new XElement("link",fixedUrl),
-
new XElement("description","the website for dream flying freely"),
-
new XElement("pubDate",DateTime.Now.ToString())
-
);
-
foreach (var article in Articles.GetArticles())
-
{
-
XElement item = new XElement("item");
-
XElement title = new XElement("title",article.Title);
-
wholeUrl = string.Format("{0}?id={1}&catelog={2}",fixedUrl,article.ID,article.Catelog);
-
XElement link = new XElement("link",wholeUrl);
-
XElement description = new XElement("description",article.Description);
-
XElement pubDate = new XElement("pubDate",article.LastMod.ToString());
-
item.Add(title,link,description,pubDate);
-
channel.Add(item);
-
}
-
rssFeed.Add(channel);
-
context.Response.Write(rssFeed);
-
}
-
public bool IsReusable
-
{
-
get { return false; }
-
}
-
-
}
-
}