In this tutorial, you will learn how to create an RSS feed within Episerver. Like most things in Episerver, if you need to display a custom RSS feed within your Episerver website, you'll need to roll-up your sleeves and get your hands a bit dirty. When I go into a lot of places, Episerver gets treated like some mythical dragon, instead of people realizing it's basically a.NET website just on steroids.
Like most 'Episerver' problems, if you need to create a custom RSS feed you can use normally .NET stuff. Specifically, the SyndicationFeed object. In today's tutorial I'm going to cover the code you'll need.
Creating Your Feed
Let's first begin by covering the code to render out your RSS feed. The whole feed will be generated by the SyndicationFeed class. The top half of the method is about setting the standard feed items like title, description, last updated date etc...
The code at the bottom of the class is all to do with feed validation. Depending on your situation, you may not care about this, but some RSS reader won't pick-up your feed unless in a very specific order, with the correct attributes and elements. If you are unsure about this, you can pop on over to the W3C RSS feed validator after you generate your feed to check its OK.
Next, I'm assuming that you're generating your feed within a normal MVC controller. The first thing you'll need to do is return XML back to the client, instead of normal HTML and the best method I found to do that from Google, was to use a custom ActionREsult.
The code above assumes you get a list of pages from Episerver. Your page objects will need to be converted to SyndicationItem. All your SyndicationItems will need to be added into the SyndicationFeed, Feeds property.
This code should be pretty simple to understand. Gets some objects, iterates through them to convert them into a different type. The last line is where the feed will be added into the requests response stream.
This custom ActionResult will take your SyndicationFeed and then add it to the response stream.
When you try and view your feed via a browser, it should look something like the screenshot above.