Using Argotic Syndication Framework with ASP.NET MVC
One of my favorite open source projects is the Argotic Syndication Framework. Argotic makes it really easy to generate RSS (and Atom and others) feeds with .NET. The library has a really clean API and has great extensibility support for RSS extensions like Media RSS.
I’ve been working almost exclusively with ASP.NET MVC the past five or six months and also been doing a lot of RSS feed generation. To make it easier to return RSS feeds from a controller action, I’ve created a new class that derives from ActionResult called RssResult. RssResult takes in a feed generated with Argotic and spits out the appropriate content type and content from the feed. Here’s what RssResult looks like:
public class RssResult : ActionResult
{
public RssFeed RssFeed { get; set; }
public RssResult(RssFeed feed) {
RssFeed = feed;
}
public override void ExecuteResult(ControllerContext context) {
context.HttpContext.Response.ContentType = "application/rss+xml";
SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();
settings.CharacterEncoding = new UTF8Encoding(false);
RssFeed.Save(context.HttpContext.Response.OutputStream, settings);
}
}
And here’s a sample controller action:
public ActionResult Index() {
PostCollection posts = PostService.ListPopular(1, 30);
RssFeed feed = new RssFeed();
feed.Channel.Title = "Managed Assembly : Popular";
feed.Channel.LastBuildDate = DateTime.Now;
foreach (var post in posts) {
feed.Channel.AddItem(new RssItem {
Author = post.User.DisplayName,
Description = post.FeedContents,
PublicationDate = post.CreateDate,
Title = post.FeedTitle,
Link = new Uri(post.FeedLink)
});
}
return Feed(feed);
}
My controller base class has the ‘Feed’ method like so:
public RssResult Feed(RssFeed feed) {
return new RssResult(feed);
}
In this example, the feed would be built up on every request. In some cases, I’ve added caching (using my CacheManager) so that the feed is only generated every 15 or 30 minutes.




