zoukankan      html  css  js  c++  java
  • asp.net生成RSS

    经常看到博客、还有很多网站中有RSS订阅,今天就来玩玩asp.net生成RSS,在网上查找了相关资料 发现just soso,如下:

    aspx

    <?xml version="1.0" encoding="utf-8"?>
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RSSDemo.aspx.cs"  ContentType="text/xml"  Inherits="WebApp1.RSSDemo"%>
    <rss version="2.0">
        <channel>
            <title>网上书店</title>
            <description>书店最新发表的图书列表</description>
        <asp:Repeater runat="server" ID="RepeatRSS">
            <ItemTemplate>
            <item>
                <title><![CDATA[<%#Eval("Title") %>]]></title>
                    <link><![CDATA[<%#Eval("ID","http://localhost:2453/WebForm1.aspx?id={0}") %>]]></link>
                 <description><![CDATA[<%#Eval("Descript") %>]]></description>
                 <pubDate><![CDATA[<%#Eval("PubDate") %>]]></pubDate>
            </item>
        </ItemTemplate>
        </asp:Repeater>
        </channel>
    </rss>

    aspx.cs文件

    namespace WebApp1
    {
        public partial class RSSDemo : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {

        ///一般这里会从数据库中查询数据,这里为了方便阅读就将就着用了
                List<BookS> listBook = new List<BookS>() {
                    new BookS(){Title="ASP.NET",Descript="详解",ID="1",PubDate=DateTime.Now.AddMonths(1)},
                    new BookS(){Title="SqlServer",Descript="详解",ID="2",PubDate=DateTime.Now.AddMonths(-2)},
                    new BookS(){Title="Oracle",Descript="详解",ID="3",PubDate=DateTime.Now.AddDays(-11)},
                    new BookS(){Title="Ajax",Descript="详解",ID="4",PubDate=DateTime.Now.AddDays(10)},
                    new BookS(){Title="SilverLight",Descript="详解",ID="5",PubDate=DateTime.Now},
                };
                RepeatRSS.DataSource = listBook;
                RepeatRSS.DataBind();
            }
        }

    ///实体类
        public class BookS
        {
            public string Title { set; get; }
            public string Descript{ set; get; }
            public string ID { set; get; }
            public DateTime PubDate { set; get; }
        }
    }

  • 相关阅读:
    JSP----获取表单参数
    application 从web.xml中获取初始化参数
    使用定时器分解任务
    无阻塞加载外部js(动态脚本元素,XMLHttpRequest注入,LazyLoad)
    ReactJs 入门DEMO(转自别人)
    带你一分钟理解闭包--js面向对象编程(转载他人)
    使用SqlBulkCopy进行批量数据插入
    AngularJsDEMO
    ECharts
    C#发送邮件DEMO
  • 原文地址:https://www.cnblogs.com/xiexingen/p/3188708.html
Copyright © 2011-2022 走看看