Creating custom RSS feed pages manually

It is possible to create a dedicated page with an RSS feed instead of using web parts. This way of creating RSS feeds is obsolete now, as syndication web parts provide a much more convenient way of creating RSS feeds.

The default installation contains a simple CMSPages\NewsRss.aspx page which shows how to build your own RSS feed. It works with news items, but you can modify the code so that it displays a different type of pages.

The following code example shows the code of the NewsRss.aspx page.

If you installed the Kentico project as a web application, you need to rename the CodeFile property on the first line to Codebehind for the code example to be functional.

<%@ Page Language="C#" AutoEventWireup="true" Inherits="CMSPages_NewsRss" CodeFile="NewsRss.aspx.cs" %>
<rss version="2.0">
  <title>News RSS</title>
 <link><![CDATA[<%=HttpContext.Current.Request.Url.AbsoluteUri.Remove(HttpContext.Current.Request.Url.AbsoluteUri.Length - HttpContext.Current.Request.Url.PathAndQuery.Length) + HttpContext.Current.Request.ApplicationPath%>]]></link> 
  <description>News RSS Feed</description>  
  <cms:cmsrepeater ID="NewsRepeater" runat="server" OrderBy="NewsReleaseDate DESC" ClassNames="cms.news"
   TransformationName="cms.news.rssitem" SelectedItemTransformationName="cms.news.rssitem"
   Path="/news/%" WhereCondition="NewsReleaseDate < GetDate()"></cms:cmsrepeater>   

The page contains only RSS elements with dynamic code. The RSS items are rendered using a CMSRepeater control with appropriate transformation.

The code behind looks like this:

using CMS.UIControls;

public partial class CMSPages_NewsRss : XMLPage
    protected void Page_Load(object sender, EventArgs e)
        Response.ContentType = "text/xml";

This code changes the output content type to XML.

How to create an RSS feed page for a different page type

If you want to display articles instead of news in your RSS feed, follow these steps:

  1. Create a new ASPX page called articles_rss.aspx.
  2. Copy and paste all code from the NewsRss.aspx file except for the <%@ Page %> directive.
  3. Change the following properties of the CMSRepeater control:
    • OrderBy: DocumentModifiedWhen DESC
    • ClassName: cms.article
    • TransformationName: cms.article.rssitem
    • SelectedItemTransformationName: cms.article.rssitem
    • Path: /%
    • WhereCondition: leave empty
  4. Add the same line of code as used in the NewsRss.aspx.cs code behind file (Response.ContentType = "text/xml") to articles_rss.aspx.cs.
  5. Create the trasformation cms.article.rssitem in the Kentico administration interface (Page Types -> edit -> Transformations):

         <guid isPermaLink="true"><![CDATA[<%# GetAbsoluteUrl(GetDocumentUrl()) %>]]></guid>
         <title><![CDATA[<%# Eval("ArticleTitle") %>]]></title>
         <description><![CDATA[<%# Eval("ArticleText") %>]]></description>
         <pubDate><%# Convert.ToDateTime(Eval("DocumentModifiedWhen")).ToString("r") %></pubDate>
         <link><![CDATA[<%# GetAbsoluteUrl(GetDocumentUrl()) %>]]></link>    

Was this page helpful?