中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

asp.net(c#) RSS功能實(shí)現(xiàn)代碼

可能還有很多未完善,但終歸可以使用了,以后再慢慢改進(jìn)!!  
以下是我RSS界面的后臺(tái)代碼,給需要的朋友提供下我的經(jīng)驗(yàn):  
復(fù)制代碼 代碼如下:
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 System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
using System.Web.Configuration;
public partial class rss : System.Web.UI.Page
{
    string   HostUrl; 
    string   HttpHead;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext context = HttpContext.Current;
        HostUrl = context.Request.Url.ToString();
        HostUrl = HostUrl.Substring(0, HostUrl.IndexOf("/", 8));
        XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, System.Text.Encoding.UTF8);
        WriteRSSPrologue(writer);
        WriteRSSHeadChennel(writer);
        string sql = "select top 10 title,id,time,content from blog_title order by time desc";
        SqlDataReader dr = dbconn.ExecuteReader(sql);
        while (dr.Read())
        {
            AddRSSItem(writer, (((DateTime)dr["time"]).ToUniversalTime()).ToString("r"), dr["title"].ToString(), HostUrl, dr["content"].ToString());
        }
        dr.Close();
        writer.Flush();
        writer.Close();
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        context.Response.ContentType = "text/xml";
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.End();
    }
    private XmlTextWriter WriteRSSPrologue(XmlTextWriter writer)
    {
        writer.WriteStartDocument();
        writer.WriteStartElement("rss");
        writer.WriteAttributeString("version", "2.0");
        writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
        writer.WriteAttributeString("xmlns:trackbac", "http://madskills.com/public/xml/rss/module/trackback/");
        writer.WriteAttributeString("xmlns:wfw", "http://wellformedweb.org/CommentAPI/");
        writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");
        return writer;
    }
    private XmlTextWriter WriteRSSHeadChennel(XmlTextWriter writer)
    {
            writer.WriteStartElement("channel");
            writer.WriteElementString("title", "編程博客(Nickeyj's Blog) - 最新日志");
            writer.WriteElementString("link", HostUrl + "/ ");
            writer.WriteElementString("description", "編程博客(Nickeyj's Blog)");
            writer.WriteElementString("copyright", "2008 www.52bcNET.com");
            writer.WriteElementString("generator", "編程博客(Nickeyj's Blog)   RSS   生成器   2.0 ");
        return writer;
    }
    private XmlTextWriter AddRSSItem(XmlTextWriter writer, string pubDate, string sItemTitle, string sItemLink, string sItemDescription)
    {
        writer.WriteStartElement("item");
        writer.WriteElementString("title", sItemTitle);
        writer.WriteElementString("link", sItemLink);
        writer.WriteElementString("description", sItemDescription);
        writer.WriteElementString("pubDate", pubDate);
        writer.WriteEndElement();
        return writer;
    }
    private XmlTextWriter AddRSSItem(XmlTextWriter writer, string sItemTitle, string sItemLink, string sItemDescription, bool bDescAsCDATA)
    {
        writer.WriteStartElement("item");
        writer.WriteElementString("title", sItemTitle);
        writer.WriteElementString("link", sItemLink);
        if (bDescAsCDATA == true)
        {
            writer.WriteStartElement("description");
            writer.WriteCData(sItemDescription);
            writer.WriteEndElement();
        }
        else
        {
            writer.WriteElementString("description", sItemDescription);
        }
        writer.WriteElementString("pubDate", DateTime.Now.ToString("r"));
        writer.WriteEndElement();
        return writer;
    }
    private XmlTextWriter WriteRSSClosing(XmlTextWriter writer)
    {
        writer.WriteEndElement();
        writer.WriteEndElement();
        writer.WriteEndDocument();
        return writer;
    }
}

AspNet技術(shù)asp.net(c#) RSS功能實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 免费毛片网站 | 日本网站在线看 | 国产精品精品久久久 | 国产在线精品一区 | 一区在线视频 | 黑人性hd | 激情自拍偷拍 | 一区二区三区亚洲视频 | 99re热精品视频 | 国产中文字幕亚洲 | 亚洲成人一级片 | 精品免费av | 精品在线一区 | 91传媒在线观看 | 久久夜视频 | 日韩欧美三区 | 完全免费在线视频 | 亚洲国产成人在线观看 | 亚州无限乱码 | 精品久久成人 | 国产精品中文字幕在线观看 | 91视频进入 | 男女羞羞视频在线免费观看 | 亚洲成人精品在线观看 | 国内精品视频在线观看 | 欧美日韩一区二区视频在线观看 | 欧美色综合一区二区三区 | 国产欧美三区 | 不卡一区 | 性一爱一乱一交一视频 | 成人免费视频久久 | 日韩免费一区二区 | 欧洲一区二区三区 | 99精品一区二区三区 | 欧美日韩在线一区二区 | 天天澡天天狠天天天做 | 福利视频大全 | 国产一区二区精品自拍 | 中文字幕 在线观看 | 亚洲一卡二卡 | 久久久久久毛片免费观看 |