Adding an RSS (Really Simple Syndication) feed to your website has never been easier. When trying to find a way to add an RSS feed to Dimecasts.net I first thought of just hand rolling my own RSS document, but that seemed like too much work. After a bit of searching and asking on Twitter I was pointed to the open source .Net library called Argotic.
In this post we will review the following steps needed to add a feed to your site.
- Creating the xml (rss feed) document for publication
- Creating an access point for the feed
- Adding the feed to your site
- Publishing your feed via Feedburner
Creating the xml (rss feed) document for publication
Setting up a feed with Argotic could not be easier, you basically just need to import the correct libraries. After you have imported the correct libraries simply add a using statement for using Argotic.Syndication. Finally you start coding. Below is the code I used (modified for this post) to create my feed.
public XDocument GenerateRSSFeed()
var rssRepository = ObjectFactory.GetInstance();
var items = rssRepository.GenerateRSSItems();
var rssFeed = new RssFeed( "Main RSS Feed for DimeCasts.Net" );
var rssChannel = new RssChannel( new Uri( "http://www.dimecasts.net" ), "Title", "Desc" );
foreach ( var item in items )
var rssItem = new RssItem
Author = "Your name here",
Title = item.Title,
Link = new Uri( item.Link),
Guid = new RssGuid(item.Link),
Description = item.Description,
PublicationDate = item.PublishDate
rssChannel.AddItem( rssItem );
rssFeed.Channel = rssChannel;
return XDocument.Parse( rssFeed.CreateNavigator().OuterXml.ToString() );
Creating an access point for the feed
In order to allow people to know about your feed, you need to create an access point. This could be something as simple as creating a static .xml document and placing it on your website. However, you will more than likely want to make the document dynamic based on the content of your site. I found the simplest way to create the access point is to create a .aspx page and change the content type from html to "text/xml".
// get the XML data/document
var feeds = new Feeds();
// Need to modify the Response type
Response.ContentType = "text/xml";
StreamWriter streamWriter = new StreamWriter( Response.OutputStream, Encoding.UTF8 );
// Make the call here to get the feed an write it out to the stream
streamWriter.Write( feeds.GenerateRSSFeed() );
// Put this code here in your html part of the page. This will cache the output for a given number
// of seconds
<%@ OutputCache Duration="600" VaryByParam="none" %>
Adding the feed to your site
In order to let the world know you have a feed, you need to expose it in your html documents. For me, I wanted every page on the site to expose this so I added it to my mast page. The code below shows how to add the pointer in your html page.
After you have added the reference to your html page you should see the RSS feed icon on your URL bar in your browser. The image to the right is of the DimeCasts site when being viewed in firefox
link title="[Your title here]" href="http://www.yourdomain.com/[rssfilehere]" type="application/rss+xml" rel="alternate"
Publishing your feed via Feedburner
Now that you have gone through the pain of setting up your feed, I would suggest you syndicate your feed and use a tracking service like Feedburner.com. One nice feature of feedburner is it allows you to track who is subscribing to your feed.
Well, I hope this helps someone.
Till next time,
[----- Remember to check out DimeCasts.Net -----]
06-10-2008 7:38 AM