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; }
        }
    }

  • 相关阅读:
    Spring Boot将Mybatis返回结果转为驼峰的三种实现方式
    Lodash-一个好用的JavaScript工具库
    基于Docker搭建LNMP环境并启用ssl证书(certbot)
    CentOS忘记mariadb/mysql root密码解决办法
    Debian如何安装curl?
    SpringBoot Controller如何接收数组参数?
    nginx web服务器概念了解 配置
    c语言二维数组的转置
    顺序表有序插入数据
    elasticsearch master_not_discovered_exception
  • 原文地址:https://www.cnblogs.com/xiexingen/p/3188708.html
Copyright © 2011-2022 走看看