一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

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

可能還有很多未完善,但終歸可以使用了,以后再慢慢改進!!  
以下是我RSS界面的后臺代碼,給需要的朋友提供下我的經(jīng)驗:  
復制代碼 代碼如下:
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功能實現(xiàn)代碼,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 国产成人福利免费观看 | 免费精品美女久久久久久久久久 | 欧美精品黄页在线观看视频 | 免费在线看黄网站 | 色黄网址 | 亚洲黄色小说图片 | 四虎永久在线精品免费影视 | 美女脱了内裤打开腿让人桶网站o | 一区二区三区在线观看免费 | 男女91视频 | 国产区视频在线观看 | 性欧美zoz0另类xxxx | 国产美女在线免费观看 | 国产精品视频国产永久视频 | 伊人成人在线视频 | 国产精品乱码一区二区三区 | 国产在线综合网 | 天天色综合天天 | 国产在线视频区 | 亚洲国产精品婷婷久久久久 | 五月丁香六月婷综合缴情在线 | 偷偷碰偷偷鲁免费视频 | 精品久久中文网址 | 久久精品国产99久久无毒不卡 | 四虎在线精品免费高清在线 | 337p亚洲精品色噜噜狠狠 | 亚洲欧美第一页 | 久久精品国产99久久99久久久 | 美国毛片亚洲社区在线观看 | 欧美高清亚洲欧美一区h | 四虎现在的网址入口 | 91精品视频免费观看 | 成人在线小视频 | 午夜看黄 | 亚洲aaaa级特黄毛片 | 91精品国产91久久久久福利 | 国产欧美一区二区精品性色99 | 国产精品色婷婷在线观看 | 色综合久久综合欧美综合图片 | 真实国产乱子伦在线观看 | 亚洲区一区 |