用C#編寫自己的RSS服務

來源:互聯網
上載者:User
對於RSS總沒什麼好主意,今天意外的搜尋到了一篇不錯的文章

Write Your Own .NET RSS Feed in C#
http://www.computorcompanion.com/LPMArticle.asp?ID=194

是通過在web.config加入*.rss的HttpHandler,並利用總設定檔配置各頻道。我試了一下,覺得不錯,很通用。試的過程遇到了一個小麻煩,IE7老是報XML檔案格式錯。拷貝原始碼,儲存後用IE7開啟又不報錯了。摸不著頭腦的時候突然想起會不會是編碼的問題呢?因為我的程式在web.config裡配置成gb2312的。

<globalization requestEncoding="gb2312" responseEncoding="gb2312" />

修改了一下文章的類,輸出時強制使用UTF8,問題解決。

context.Response.ContentType = "text/xml";            
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Write("<?xml version=\"1.0\"?>");
context.Response.Write(cachedChan);

文章有相關代碼的下載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.