1.在线生成RSS聚合页。
(1)创建Rss.aspx
<%@ Page language="c#" Codebehind="Rss.aspx.cs" AutoEventWireup="false" Inherits="LiTianPing.Rss" %>
只留下这一行,其余的都删掉。
(2)后台代码;Rss.aspx.cs
private void Page_Load(object sender, System.EventArgs e)
{
Response.ContentType="text/xml";
Response.Write(GetRSS());
}
/// <summary>
/// 取得聚合文章
/// </summary>
/// <returns></returns>
public string GetRSS()
{
News t=new News();//自己的业务类
DataSet ds=t.GetListByClass(1);//根据类别得到数据
StringBuilder strCode=new StringBuilder();
strCode.Append("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>");
strCode.Append("<rss version=''2.0'' xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");
strCode.Append(" xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\" ");
strCode.Append(" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\" xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\">");
strCode.Append("<channel>");
strCode.Append("<title>李天平RSSDemo</title>");
strCode.Append("<link>http://"+Request.ServerVariables["SERVER_NAME"]+"</link> ");
strCode.Append("<description>天道酬勤</description> ");
strCode.Append("<copyright>Copyright 2005</copyright> ");
foreach(DataRow row in ds.Tables[0].Rows)
{
string Id=row["Id"].ToString();
string title=row["title"].ToString();
string description=row["description"].ToString();
string pubdate=row["pubdate"].ToString();
string ClassId=row["ClassId"].ToString();
//string author=row["author"].ToString();
strCode.Append("<item>");
strCode.Append("<title>"+title+"</title>");
strCode.Append("<link>http://"+Request.ServerVariables["SERVER_NAME"]+"/NewsShow.aspx?ID="+Id+"</link>");
strCode.Append("<subject>"+description+"</subject>");
&n |