RSS 订阅功能的实现
2010-03-02 18:39
465 查看
很多站点多会用到RSS订阅功能,今天写了个,留个笔记。
我们可以用.aspx,.ashx文件构建xml文件,输出xml 可以通过 XmlTextWriter实例化来输出,也可以直接输出。
1.利用XmlTextWriter输出
代码
protected String uid = String.Empty;
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
uid = HttpContext.Current.Request.QueryString["id"].ToString();
Response.ContentType = "text/xml";
Response.Charset = "GB2312";
Response.Write(GetRSS());
}
#region
/// <summary>
/// 取得聚合文章
/// </summary>
public string GetRSS()
{
UserBasicModelInfo info = UserBasic.GetBasicList(uid);
DataSet ds = wdxt_Common.GetSomeData.GetDataNum("VW_NEWLOG", "*", "LOGSEECOMPETENCE=1 and userinfoid=" + uid + "", "addtime desc ", 100);
String strRSS = "<?xml version=\"1.0\" encoding=\"gb2312\" ?><rss version=\"2.0\">";
strRSS += "<channel>";
strRSS += "<title>" + info.TrueName + "的博客</title>";
strRSS += "<link>" + Application["Url"] + "/Myspace/Space/Rss1.aspx?id=" + uid + "</link>";
strRSS += "<description></description>";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string Logid = ds.Tables[0].Rows[i]["logid"].ToString();
string LogContent = ds.Tables[0].Rows[i]["LogContent"].ToString();
string Title = ds.Tables[0].Rows[i]["logtitle"].ToString();
String LogAddTime = ds.Tables[0].Rows[i]["Addtime"].ToString();
string truename = ds.Tables[0].Rows[i]["TrueName"].ToString();
strRSS += "<item>";
strRSS += "<title>" + Title + "</title>";
strRSS += "<link>" + Application["Url"] + "/Blog/info/" + Logid + "</link>";
strRSS += "<pubDate>" + LogAddTime + "</pubDate>";
strRSS += "<copyright>" + truename + "</copyright>";
strRSS += "<description><![CDATA[" + LogContent + "]]></description>";
strRSS += "</item>";
}
strRSS += "</channel>";
strRSS += "</rss>";
return strRSS;
}
#endregion
参考:1. 微软的CSASPNETRssFeeds
2. 我的源码
3. 可能还要为站点添加到别的网站的RRS链接,可以看看博客园的。
我们可以用.aspx,.ashx文件构建xml文件,输出xml 可以通过 XmlTextWriter实例化来输出,也可以直接输出。
1.利用XmlTextWriter输出
代码
protected String uid = String.Empty;
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
uid = HttpContext.Current.Request.QueryString["id"].ToString();
Response.ContentType = "text/xml";
Response.Charset = "GB2312";
Response.Write(GetRSS());
}
#region
/// <summary>
/// 取得聚合文章
/// </summary>
public string GetRSS()
{
UserBasicModelInfo info = UserBasic.GetBasicList(uid);
DataSet ds = wdxt_Common.GetSomeData.GetDataNum("VW_NEWLOG", "*", "LOGSEECOMPETENCE=1 and userinfoid=" + uid + "", "addtime desc ", 100);
String strRSS = "<?xml version=\"1.0\" encoding=\"gb2312\" ?><rss version=\"2.0\">";
strRSS += "<channel>";
strRSS += "<title>" + info.TrueName + "的博客</title>";
strRSS += "<link>" + Application["Url"] + "/Myspace/Space/Rss1.aspx?id=" + uid + "</link>";
strRSS += "<description></description>";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string Logid = ds.Tables[0].Rows[i]["logid"].ToString();
string LogContent = ds.Tables[0].Rows[i]["LogContent"].ToString();
string Title = ds.Tables[0].Rows[i]["logtitle"].ToString();
String LogAddTime = ds.Tables[0].Rows[i]["Addtime"].ToString();
string truename = ds.Tables[0].Rows[i]["TrueName"].ToString();
strRSS += "<item>";
strRSS += "<title>" + Title + "</title>";
strRSS += "<link>" + Application["Url"] + "/Blog/info/" + Logid + "</link>";
strRSS += "<pubDate>" + LogAddTime + "</pubDate>";
strRSS += "<copyright>" + truename + "</copyright>";
strRSS += "<description><![CDATA[" + LogContent + "]]></description>";
strRSS += "</item>";
}
strRSS += "</channel>";
strRSS += "</rss>";
return strRSS;
}
#endregion
参考:1. 微软的CSASPNETRssFeeds
2. 我的源码
3. 可能还要为站点添加到别的网站的RRS链接,可以看看博客园的。
相关文章推荐
- RSS 订阅功能的实现
- RSS 订阅功能的实现
- 利用reids实现发布订阅的功能
- Jedis实现Publish/Subscribe功能(发布和订阅)
- Jedis实现发布订阅功能
- asp.net(c#) RSS功能实现代码
- 微信订阅号天气预报功能的实现(java版)
- nodejs使用RSS实现Ghost博客搜索功能
- 博客新增订阅功能RSS 时时关注博友更新文章
- Asp.net实现网站的RSS功能
- java实现RSS功能
- 现实简单的RSS订阅功能,对RSS feeds的分析
- 在JAVA项目中实现RSS功能
- Redis 订阅功能实现
- 为Jekyll博客添加RSS feed订阅功能
- 为Jekyll博客添加RSS feed订阅功能
- node.js+redis+express 实现发布订阅功能
- 12.springboot使用redis的订阅功能实现消息队列
- 为Jekyll博客添加RSS feed订阅功能
- (文章)分享功能 & RSS订阅到Google,Yahoo,qq邮箱的接口源码