Home » Articles


Sponsored links

CodeDigest Navigation

Technology News
No News Feeds available at this time.

Community News
No News Feeds available at this time.
Generate RSS Feed in ASP.Net

By Satheesh babu
Posted On Jun 23,2008
Article Rating:
Be first to rate
this article.
No of Comments: 1
Category: ASP.Net
Print this article.

Generate RSS Feed in ASP.Net


RSS feed is an xml formatted document that gives user the capability to read frequently updated contents on our websites without visiting our site. RSS feed has become one of the most sophisticated mechanism to share information on the internet world. It is one of the web 2.0 features which allows users to read their relevant information’s available on the internet. All we need to do is, get the RSS feed URL from different sites of our interest and subscribe it on our RSS reader. Before moving to actual implementation of RSS feed we will understand the format of RSS feeds that a RSS reader can consume.

For example, CodeDigest Rss feed will look like,

<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0">


  <title> Latest Articles</title>


  <description>Latest articles hosted on</description>


  <title>Useful Datagrid Tips</title>

  <description>There are some frequent queries that are being asked in most of the forums and UG’s regarding datagrid. I have compiled a list of useful tips from my previous posts and posted it here.</description>


  <pubDate>4/29/2008 9:47:12 AM</pubDate>





As we can see the above XML, the whole contents are packed inside <rss> tag. The actual information about the posts is kept inside <item> tag which in turn is packed inside a <channel> tag. Read the history and specification of RSS here. Moving forward this article will help us understand constructing an RSS feeds for our sites.


What we need to do?

Generating RSS feed for our website is nothing but emitting the frequently updated data in the above specified XML format. It can be done by constructing the XML document and performing a Response.Write of the constructed XML document.


What should we use?

Our requirement can be achieved by performing a Response.Write on an ASPX page. But, in this article we will generate our RSS feed using HttpHandler instead of an ASPX page. There are some advantages in using HttpHandler over an ASPX pages, an ASPX page will have a series of events like OnInit, Page load, etc  which is not at all required in our case. These page level events are over head since we just want to get the data from database and construct a XML document and output the raw xml.



With the RSS feed XML format in mind, we can construct XML using XmlTextWriter class. Include an HttpHandler to our project by right clicking solution and clicking “Add New Item”. Refer the below figure.




<%@ WebHandler Language="C#" Class="Rss" %>


using System;

using System.Web;

using System.Data;

using System.Text;

using System.Xml;

using DataAccess;



public class Rss : IHttpHandler {


    ArticleDAO articleDAO = new ArticleDAO();


    public void ProcessRequest (HttpContext context) {


        // Clear any previous output from the buffer




        context.Response.ContentType = "text/xml";


        XmlTextWriter cdRSS = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8);






        cdRSS.WriteAttributeString("version", "2.0");       




        cdRSS.WriteElementString("title", " Latest Articles");


        cdRSS.WriteElementString("link", "");


        cdRSS.WriteElementString("description", "Latest articles hosted on");


        cdRSS.WriteElementString("copyright", "Copyright 2008 - 2009 All rights reserved.");


       //Connect database to get the data

        DataTable dtArticles = articleDAO.GetArticlesForRss();


        for (int i = 0; i < dtArticles.Rows.Count; i++)


       //Build Item tags with the data from database



            cdRSS.WriteElementString("title", dtArticles.Rows[i]["Title"].ToString());


            cdRSS.WriteElementString("description", dtArticles.Rows[i]["description"].ToString());


            cdRSS.WriteElementString("link", "http://"+ context.Request.Url.Host + dtArticles.Rows[i]["URL"].ToString());


            cdRSS.WriteElementString("pubDate", dtArticles.Rows[i]["ApprovedOn"].ToString());



















    public bool IsReusable {

        get {

            return false;





You can read more about HttpHandler from the articles in the reference section.



HttpHandler – Part 1

HttpHandler – Part 2



Thus, we have understood implementation of one of the very famous and extremely useful Web 2.0 feature. To consume the RSS feed in our ASP.Net sites you can follow the article here.

Happy Coding!!

Similar Articles
You can contribute to CodeDiget.Com:
Donate to
Article Feedback
Hi - what is articleDAO?