在自己的网站上使用RSS订阅功能
要增加RSS订阅功能其实很简单
就是填写一个规定好的xml文档,按照要求填好就可以实现
具体的步骤如下:
这是在网上查到的RSSxml文档
<?xml version="1.0"?> <rss version="2.0"> <channel> <title>网站标题</title> <link>网站首页地址</link> <description>描述</description> <copyright>授权信息</copyright> <language>使用的语言(zh-cn表示简体中文)</language> <pubDate>发布的时间</pubDate> <lastBuildDate>最后更新的时间</lastBuildDate> <generator>生成器</generator> <item> <title>标题</title> <link>链接地址</link> <description>内容简要描述</description> <pubDate>发布时间</pubDate> <category>所属目录</category> <author>作者</author> </item> </channel> </rss>
其实真正用到的并没有那么多,这里我用一个Rss.aspx来实现RSS订阅功能
前台代码如下:
<?xml version="1.0" ?> <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RSS.aspx.cs" Inherits="BookShop.RSS" %> <rss version="2.0"> <channel> <title>网上书城</title> <link>http://localhost:1341/Index.aspx</link> <description>本书城提供最新最全的开发者图书资料</description> <copyright>网上书城</copyright> <language>zh-cn</language> <asp:Repeater runat="server" ID="rssRepeater"> <ItemTemplate> <item> <title><%#Eval("BookName") %></title> <link><%#Eval("Id", "<a href='http://localhost:1341/BookDetail.aspx?id={0}'></a>")%></link> <pubDate><%#Eval("PublishDate")%></pubDate> <author><%#Eval("Author")%></author> <description><![CDATA[<%#Eval("ContentDescription")%>]]></description> </item> </ItemTemplate> </asp:Repeater> </channel> </rss>注意:
该文件为xml文件,xml文档的说明必须放在第一行
<![CDATA[...]]>,放在之间的数据不会被解析,原样输出(放在里面的数据可能是不符合xml格式的,如果不加浏览器会报错)
对比上面两段代码
其实就是用一个Repeater对item进行循环而已
在后台对Repeater进行数据绑定,就会将数据显示在RSS订阅的页面上