RSS的发布
ASPX页面
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Rss.aspx.cs" Inherits="Rss" ContentType="text/xml" %>
<asp:Repeater id="rptRss" runat="server">
<HeaderTemplate>
<rss version="2.0">
<channel>
<title>第三波网络书店</title>
<link>www.apatech.com</link>
<description>第三波网络书店</description>
<copyright>Copyright 2007-2009 by 第三波网络书店</copyright>
</HeaderTemplate>
<ItemTemplate>
<item>
<title><%# EnCode(Eval("Title"))%></title>
<author><%# EnCode(Eval("Author"))%></author>
<description><%# EnCode(Eval("ContentDescription"))%></description>
<link><%# EnCode(GetUrl(Eval("ID")))%></link>
<pubDate>
<%# EnCode(string.Format("{0:D}", Eval("PublishDate")))%>
</pubDate>
</item>
</ItemTemplate>
<FooterTemplate>
</channel>
</rss>
</FooterTemplate>
</asp:Repeater>
CodeFile="Rss.aspx.cs" Inherits="Rss" ContentType="text/xml" %>
<asp:Repeater id="rptRss" runat="server">
<HeaderTemplate>
<rss version="2.0">
<channel>
<title>第三波网络书店</title>
<link>www.apatech.com</link>
<description>第三波网络书店</description>
<copyright>Copyright 2007-2009 by 第三波网络书店</copyright>
</HeaderTemplate>
<ItemTemplate>
<item>
<title><%# EnCode(Eval("Title"))%></title>
<author><%# EnCode(Eval("Author"))%></author>
<description><%# EnCode(Eval("ContentDescription"))%></description>
<link><%# EnCode(GetUrl(Eval("ID")))%></link>
<pubDate>
<%# EnCode(string.Format("{0:D}", Eval("PublishDate")))%>
</pubDate>
</item>
</ItemTemplate>
<FooterTemplate>
</channel>
</rss>
</FooterTemplate>
</asp:Repeater>
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;
using MyBookShop.BLL;
public partial class Rss : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
rptRss.DataSource =
BookManager.GetBooks(" Top 20 Id, Title,PublisherId, Author,
SubString(ContentDescription,0,200) as ShortContent,
PublishDate ", 0, " PublishDate desc");
rptRss.DataBind();
}
/// <summary>
/// 执行html编码
/// </summary>
/// <param name="obj">绑定的数据</param>
/// <returns></returns>
public string EnCode(object obj)
{
return Server.HtmlEncode(obj as string);
}
/// <summary>
/// 由于是开发服务器,需生成路径
/// </summary>
/// <param name="obj">路径id</param>
/// <returns></returns>
public string GetUrl(object obj)
{
return "http://"+Request.ServerVariables["HTTP_HOST"].ToString()
+ "/web/BookDetail.aspx?bid=" + obj as string;
}
}
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;
using MyBookShop.BLL;
public partial class Rss : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
rptRss.DataSource =
BookManager.GetBooks(" Top 20 Id, Title,PublisherId, Author,
SubString(ContentDescription,0,200) as ShortContent,
PublishDate ", 0, " PublishDate desc");
rptRss.DataBind();
}
/// <summary>
/// 执行html编码
/// </summary>
/// <param name="obj">绑定的数据</param>
/// <returns></returns>
public string EnCode(object obj)
{
return Server.HtmlEncode(obj as string);
}
/// <summary>
/// 由于是开发服务器,需生成路径
/// </summary>
/// <param name="obj">路径id</param>
/// <returns></returns>
public string GetUrl(object obj)
{
return "http://"+Request.ServerVariables["HTTP_HOST"].ToString()
+ "/web/BookDetail.aspx?bid=" + obj as string;
}
}