#region using
using System;
using System.Data;
using System.Text;
using System.Web;
#endregion
namespace Rss
{
public class CreatRss : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/xml";//设置输出内容为XML格式
#region 预备数据
DataTable dt = new DataTable("RssData");
dt.Columns.Add("title");
dt.Columns.Add("link");
dt.Columns.Add("description");
dt.Columns.Add("author");
dt.Columns.Add("pubDate", typeof(DateTime));
dt.Rows.Add(new object[] { "IHttpHandlerFactory的运用(权限控制)1", "http://www.cnblogs.com/leleroyn/archive/2008/06/11/1217432.html", "看了Unity&WebForm(1): 自定义IHttpHandlerFactory使用Unity对ASP.NET Webform页面进行依赖注入,我也按奈不住,把上次几个项目里的自定义IHttpHandlerFactory实现权限控制的方案写了下来。。写的匆忙,而且自已水平又有限,望大家指点~0~", "Ants", DateTime.Parse("2008-06-11 15:52") });
dt.Rows.Add(new object[] { "IHttpHandlerFactory的运用(权限控制)2", "http://www.cnblogs.com/leleroyn/archive/2008/06/11/1217432.html", "看了Unity&WebForm(1): 自定义IHttpHandlerFactory使用Unity对ASP.NET Webform页面进行依赖注入,我也按奈不住,把上次几个项目里的自定义IHttpHandlerFactory实现权限控制的方案写了下来。。写的匆忙,而且自已水平又有限,望大家指点~0~", "Ants", DateTime.Parse("2008-06-12 15:52") });
dt.Rows.Add(new object[] { "IHttpHandlerFactory的运用(权限控制)3", "http://www.cnblogs.com/leleroyn/archive/2008/06/11/1217432.html", "看了Unity&WebForm(1): 自定义IHttpHandlerFactory使用Unity对ASP.NET Webform页面进行依赖注入,我也按奈不住,把上次几个项目里的自定义IHttpHandlerFactory实现权限控制的方案写了下来。。写的匆忙,而且自已水平又有限,望大家指点~0~", "Ants", DateTime.Parse("2008-06-13 15:52") });
DataView dv = dt.DefaultView;
dv.Sort = "pubDate desc";
#endregion
StringBuilder str = new StringBuilder();
str.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
#region 频道信息区
str.Append("<rss version=\"2.0\">"); //起名RSS的版本
str.Append("<channel>");//频道
str.Append("<title>拼吾爱程序人生</title>");//频道的标题
str.Append("<link>http://www.pin5i.com</link>");
str.Append("<description>致力于提供有价值的编程技术、IT资讯和服务</description>");
str.Append("<author>Ants</author>");
#endregion
内容列表区#region 内容列表区
for (int i = 0; i <= 2; i++)
{
str.Append("<item>");
str.Append(string.Format("<title>{0}</title>", context.Server.HtmlEncode(dv["title"].ToString())));//编码的标题
str.Append(string.Format("<link>{0}</link>", dv["link"].ToString()));
str.Append(string.Format("<description>{0}</description>", context.Server.HtmlEncode(dv["description"].ToString())));//编码项目的介绍
str.Append(string.Format("<author>{0}</author>", dv["author"].ToString()));
str.Append(string.Format("<pubDate>{0}</pubDate>", dv["pubDate"].ToString()));
str.Append("</item>");
}
#endregion
str.Append("</channel>");
str.Append("</rss>");
context.Response.Write(str.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
}