RSS

RSS(也叫聚合内容,Really Simple Syndication)是一种描述和同步网站内容的格式,是目前使用最广泛的XML应用。个人认为,它就是资源共享模式的延伸。

 用asp.net实现RSS功能非常简单。好了,直接贴代码吧,建立Article.aspx,然后代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Article.aspx.cs" Inherits="Web.rss.Article"%><%@ OutputCache Duration="600" VaryByParam="none"%><?xml version="1.0" encoding="gb2312" ?>  
<rss version="2.0">
<channel>
<title><![CDATA[www.SvnHost.cn最新文章]]></title>
<link>http://www.SvnHost.cn</link>
<description><![CDATA[专业SVN托管服务-源代码版本管理-SVN Hosting Service]]></description>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<item id="<%# Container.ItemIndex + 1%>">
<title><![CDATA[<%# Eval("title")%>]]></title>
<tags><![CDATA[<%# Eval("tag")%>]]></tags>
<link>http://www.svnhost.cn/Article/<%# Eval("id")%>.shtml</link>
<description><![CDATA[<%# Eval("contents")%>]]></description>
</item>
</ItemTemplate>
</asp:Repeater>
</channel>
</rss>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db %>"
SelectCommand
="SELECT TOP 50 * FROM [t_Article] ORDER BY [id] DESC">
</asp:SqlDataSource>

后台CS代码如下:

 

using System;  
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Web.rss
{
publicpartialclass Article : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
Response.ContentType
="text/xml";
}
}
}
posted @ 2013-03-18 13:55  fang_beny  阅读(143)  评论(0编辑  收藏  举报