Recently I was working on providing and consuming an RSS feed for a Silverlight project. One of the handy (but often overlooked) things possible with asp.net is the ability to set the content type at the page level. So using that trick along with a SqlDataSource and a repeater, you can put together a RSS feed (admittedly a very simple one) in as single aspx file – no code behind needed.

<%@ Page Language="C#" ContentType="text/xml" %>

<asp:repeater runat="server" DataSourceId="sdsFeed">
    <HeaderTemplate>
        <rss version="2.0">
            <channel>
                <title>QuickRss Test Feed</title>
                <link>http://quisitive.net/feed</link>
                <description>This is the feed description.</description>
    </HeaderTemplate>
    <ItemTemplate>
        <item>
            <title><%# Eval("title") %></title>
            <description><%# Eval("description") %></description>
            <pubdate><%# Eval("pubdate") %></pubdate>
        </item>
    </ItemTemplate>
    <FooterTemplate>
            </channel>
        </rss>
    </FooterTemplate>
</asp:repeater>

<asp:SqlDataSource ID="sdsFeed" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT title, description, pubdate FROM rssData">
</asp:SqlDataSource>

Calling the page above results in the following simple RSS feed.

Resulting RSS data

Although this is not exactly a Silverlight tip, it may come in handy.