Awesome ASP.NET 2.0 RSS ToolKit Released

Dmitry on the ASP.NET Team posted an awesome RSS Toolkit for ASP.NET 2.0 on his blog earlier tonight.  It provides a ton of great support for both consuming and exposing RSS from ASP.NET 2.0 applications, and ships with full source code.

 

March 26th, 2006 Update: Dmitry just updated the origional download here.

 

Some of the features/scenarios in the new RSS Toolkit include:

 

RSS Data-binding Control Support

 

You can now declaratively databind any ASP.NET control to the new RSSDataSource control provided in the toolkit.  For example, to build a simple blog post aggregator for my blog you could follow the below steps with the free Visual Web Developer tool:

 

1) Create a new blank page

 

 

2) Drag/Drop the standard ASP.NET DataList control on the page, choose the “New DataSource” option from the smart-task:

 

 

3) Select the RSSDataSource control to bind to (note: this will automatically be populated in the datasource dialog window if the RSSDataSource control has been added to the VS toolbox):

 

 

4) In the RSSDataSource dialog that pops-up, type in the URL to the RSS feed you want to databind to:

 

 

5) The RSSDataSource control will then request the schema for the RSS feed and expose it to VS – which will then populate the <asp:datalist> control with an <itemTemplate> that is automatically populated with data-binding expressions for each of the RSS schema fields from the remote RSS source:

 

 

6) You can then switch into template editing mode in the WYSIWYG designer, or go into source-view to remove some of the fields and just leave the RSS fields you want to bind to.  Here is a sample page with a DataList template that binds to the link and title RSS item fields:

 

<%@ Register Assembly="RssToolkit" Namespace="RssToolkit" TagPrefix="RssToolkit" %>

 

<html>

<head runat="server">

    <title>ScottGu Feed</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

        <h2>ScottGu Blog Feed</h2>   

       

        <asp:DataList ID="DataList1" runat="server" CellPadding="4" DataSourceID="RssDataSource1" ForeColor="#333333">

            <ItemTemplate>

                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("link") %>' Text='<%# Eval("title") %>'></asp:HyperLink>

            </ItemTemplate>

        </asp:DataList>

       

        <RssToolkit:rssdatasource id="RssDataSource1" runat="server" url="http://weblogs.asp.net/scottgu/Rss.aspx">

        </RssToolkit:rssdatasource>

 

    </div>

    </form>

</body>

</html>

 

7) I can then run the page and get this output:

 

 

As you can see above, the DataList is now bound to the data returned from the remote RSS feed on my site.

 

What is really cool is that the RSSDataSource control will cache the RSS data to avoid hitting it remotely on each request – so that you can efficiently add this type of blog aggregation functionality to your site and not have to worry about your performance slowing down.

 

Strongly Typed RSS API Support

 

The RSS Toolkit also adds support for creating a strongly-typed object model over a remote RSS feed.  This allows you to program against RSS data in a clean, easy way.  You can do this one of two ways:

 

1) Using the rsssdl.exe utility that ships with the toolkit.  This is a command-line tool that generates a strongly-typed class library based on a provided RSS URL feed (sort of like wsdl.exe does for web-services).  For example, I could use it against my ScottGu RSS blog feed like so to generate a Scottgu.cs file containing C# classes that provide a strongly-typed object model around it:

 

 

I could then add the generated “scottgu.cs” file to my project and instantiate and use the class framework to programmatically databind the RSS channel’s items against a GridView (note that each of the Items is strongly typed as a "ScottGuChannelItem" -- and has a strongly-typed object model based on the schema of the RSS feed):

 

ScottGuChannel channel = ScottGuChannel.LoadChannel();

 

GridView1.DataSource = channel.Items;

GridView1.DataBind();

 

or alternatively:

 

2) The RSS toolkit also ships with a new ASP.NET 2.0 build-provider that allows you to declaratively add .rssdl file definitions in your app_code directory.  For example like so:

 

<rssdl>

    <rss name="ScottGu" url="http://weblogs.asp.net/scottgu/rss.aspx" />

</rssdl>

 

This will then automatically generate and build a RSS channel proxy into your project for you to use (no command line tool usage required).

 

RSS Publishing Support

 

The RSS Toolkit also adds support for easily and efficiently publishing RSS feeds from an ASP.NET 2.0 application.  For example, to build an RSS feed on your site with it you can now do the following:

 

Step 1) Add a .rss sample definition file to your app_code directory that provides some sample schema for what you want the RSS feed to look like.  For example, a Sample5.rss file like so:

 

<?xml version="1.0" encoding="utf-8"?>

<rss version="2.0">

  <channel>

    <title>Sample Channel</title>

    <link>~/scenario5.aspx</link>

    <description>Sample Channel Example</description>

    <ttl>10</ttl>

    <name></name>

    <user></user>

    <item>

      <title></title>

      <description></description>

      <link></link>

    </item>

  </channel>

</rss>

 

This will then create a strongly typed object-model for the RSS schema, as well as build a default RSSHandlerBaseClass for you to use to publish it within an ASP.NET .ashx handler file.

 

Step 2) Create a Sample5.ashx handler file in VS 2005 or Visual Web Developer to expose the channel information.  You can sub-class the RSSHandlerBaseClass automatically defined from the sample schema above to publish the RSS data in a strongly typed way:

 

<%@ WebHandler Language="C#" Class="scenario5" %>

 

using System;

using System.Web;

 

public class scenario5 : Sample5HttpHandlerBase {

   

    protected override void PopulateChannel(string channelName, string userName) {

       

        Channel.Name = channelName;

 

        Channel.Items.Add(

            new Sample5Item("Scenario1",

                            "Consuming RSS feed using RssDataSource",

                            "~/scenario1.aspx"));

        Channel.Items.Add(

            new Sample5Item("Scenario2",

                            "Consuming RSS feed using ObjectDataSource",

                            "~/scenario2.aspx"));

        Channel.Items.Add(

            new Sample5Item("Scenario3",

                            "Consuming RSS feed programmatically using strongly typed classes",

                            "~/scenario3.aspx"));

        Channel.Items.Add(

            new Sample5Item("Scenario4",

                            "Consuming RSS feed programmatically using late bound classes",

                            "~/scenario4.aspx"));

    }   

}

 

Note that all operations within the RSS handler are strongly typed (meaning you’ll get intellisense support, and a compile error if you mistype something).

 

Step 3) When you hit the URL to the above handler you’ll then get back an RSS XML feed that you can easily subscribe to:

 

 

Note above how the channel item paths are fully qualified in the output RSS XML, but are using the “~” syntax in the .ashx handler.  The RSS toolkit adds a nice feature which is the ability for a developer to use the “~” syntax to automatically fix up fully qualified path statements from the channel handler (that way the paths will be correct regardless of whatever server or virtual directory hierarchy the application is deployed on).

 

Personalized RSS Feed Integration with ASP.NET Authentication System

 

One of the tricks people are doing these days with RSS is to enable people to subscribe to feeds that are personalized for them.  They often do this by adding a query-string parameter to the RSS feed that contains a unique identifier to map the URL to a specific account name on the server (allowing a user for example to publish and subscribe to their private calendar or task-list or contact-list information).

 

The RSS Toolkit allows you to easily build these types of apps and integrate them with the ASP.NET membership and authentication system.  Note how in the handler above there is a “username” parameter to the PopulateChannel method.  ASP.NET will look for an encrypted username value on the incoming RSS feed URL, and automatically decrypt and pass the username to this method when it is supplied (you could then write code within this method to hit a database and pull back only the items for that particular user).

 

To embed the encrypted user-name within the RSS feed URL, you can either get the value via an API call, or generate the RSS URL link using the new declarative RSSHyperlink control and setting the IncludeUserName=”true” property to true:

 

<RssToolKit:RssHyperLink runat="server" IncludeUserName="True" NavigateUrl="~/scenario6.ashx">Personalized RSS Feed Sample</RssToolKit:RssHyperLink>

 

When a user clicks on this feed it will include their username encrypted within the URL.  When they copy/paste the feed link into a blog reader (for example: to subscribe to it), it will then remember the user’s identity and allow them to always have a personalized view of the data.

 

Automatic Caching of RSS Feeds

 

The RSS Toolkit automatically includes built-in caching logic so that RSS feed data is cached locally instead of fetched each time it is accessed/used.  The RSS Toolkit supports caching this information both in-memory, as well as persistently to disk (for example: to survive worker process restarts or application resets). 

 

The benefit of this built-in caching integration is that you can efficiently subscribe and pull RSS data from a variety of remote sources without having to worry about your server blocking on remote network calls all the time.  Note that the RSS toolkit by default uses an RSS channel’s TTL setting to control the cache duration semantics for you.

 

Summary

 

The new ASP.NET RSS Toolkit provides a ton of cool RSS functionality to take advantage of, and allows you to easily integrate RSS within both your sites and applications.  RSS is no longer just about blogging – it is now a super common data format for people to publish and subscribe to lots of different types of information (for example: check out this sample I built using the December CTP build of Atlas for a sample “Ajax Task List App” that publishes to-do items using RSS).

 

You can download the RSS Toolkit from here.  Best of all it is free, and all of the Toolkit’s source code is included with the sample.  It includes a number of great scenario samples that you can walkthrough to quickly learn how to use it. 

 

The RSS Toolkit has been written to work in medium trust security scenarios – so you can run it on shared hosting servers (note: to consume remote RSS feeds the hosted server will need to allow remote out-bound http requests).  Click here to learn more about how to find a hoster that provide inexpensive ASP.NET 2.0 and SQL hosting.

 

Special thanks go to Dmitry for building this RSS Toolkit in his spare time.  If you download and use it please make sure to thank him through his blog. J

 

Hope this helps,

 

Scott 

 

P.S. In case you missed it in December, Dmitry also built and published a great disk-based output caching module for ASP.NET 2.0 as well.  You can download it here.

 

48 Comments

  • Excellent Control ...

    it will help me more to collect all my favorite blogs in my site easly ;)

  • Super! Thanks for sharing this.

  • Thanks for info.But I don't get it,why you need something more complicated than XmlDataSource+simple xsl?You can achieve similar results you present here but more easily IMHO.

  • Hello,



    This is a nice solution. I just hope that the sourcecode is available for VB.NET also. Your last two solutions (1) Table Provider and (2) Online WAT solution were both important for us and unfortunately both were in C# only. This just disappoints us, as we cannot use this two great solutions as on date without VB.Net support. Pl. make sure to make sourcecode available in both the languages. Hope you understand our problems mr. scott.

  • Great One ...



    I'll try to put this in my future .net 2.0 blog :D



    Bye from Spain

  • Hi Murali,



    I believe if you have any control that derives from the DataSource control base class in your VS toolbox, it will show up as an option in the Data Source Wizard (we did this work to enable cool datasource controls like the RSS one to be built after the product shipped).



    Note that the full shource code for the RSSDataSource control is included in the download above -- so you can see exactly how it is built there.



    Hope this helps,



    Scott

  • Hi Andrey,



    There are three benefits to the RSSDataSource control over the built-in XMLDataSource control:



    1) It includes built-in caching of the RSS data, and can use the RSS feed's TTL (time to live) value to automatically cache the RSS data for you. This enables much more scalable solutions.



    2) It is easier to use than XMLDataSource for RSS -- and avoids you having to write any custom transforms or databinding expressions to format the results.



    3) It is a useful sample of how to build a DataSourceControl. We are going to be increasing the documentation on DataSourceControl's in the future (several people have asked for this). Samples like this also hopefully help.



    Hope this helps,



    Scott

  • Scary! This asp.net 2.0 stuff is soooooo damn good it's scary. Thanks Scott! :)

  • This new Toolkit is awesome. Now I don't have to worry about writing one from scratch it will save so much time now. RSS is no longer going to be a problem like it was.

  • 1)Caching is not so difficult to implement using existent Application.Cache infrastructure-simply insert intermediate code between XMlDataSource control and feed source that will be doing caching before hand off xml to DS.



    2)Not sure about this...several xsls already exists,I don't have to write it myself and

    &lt;XmlDataSource src=&quot;feed&quot; Transform=&quot;&quot;/&gt; looks nice to me+universal,I must add!;-)At last,if you need custom formatting modifying xsl is much more flexible and generic approach IMO.



    3)I can't say anything against this;-)

    But there's two ways to &quot;web enable&quot; custom data model-custom providers(for existent datasource-I mean custom XmlReader/IXPathNavigable,for example) and custom DataSources.What approach you take is up to you of course,but it's not so obvious to me that DataSource is preferable in this case.



    Thanks.

  • I have'nt downloaded it yet, but its posted by you Scott, so it has to be awesome :)) (also i will thank to Dmitry on his blog personally).



    Beleive me you are day by day becoming my inspiration for so many things.


  • Nice one, making RSS easier

  • Hi Scott,



    First let me say that I really enjoy reading your blog, keep up the good work (and so on and so forth...) :)



    Second, a while ago you made two great blog posts about a Data Tutorial scenarios in which you said there would be comming more of the same in the future. Have I missed a reference to them somewhere or are they still comming in the future? Or has the blog thread been discontinued?



    Cheers,

    Tommy

  • Hi Tommy,



    The data tutorials are still coming -- I've been fairly busy the last month which is part of the reason for the slow-down on them. I hope to have another one published, though, in the next week or so.



    Hope this helps,



    Scott

  • Excellent article. Thanks for the screenshots and great detail.

  • Great Work.. Thanks..

  • more tutorials on how to use this control will be great!!

  • Am looking into learning more RSS Data Feeds and possible use of them on our sites (currently ASP Classic, but moving to ASP .NET) and was wondering if there was a way to use a parameter much like username is used in the above example to give specific content to the feeds. Let's say a State value, so a user can alsways get latest information about a certain State.

  • Hi John,



    I believe you want do that (Dmitry would be the expert -- you might want to ask him on his blog). The RSS toolkit also supports authentication -- so you can also vary feeds by authenticated user.



    Hope this helps,



    Scott

  • Perfect control!!!



    Thanks.

  • Thanks for the great info on the RSS Toolkit Scott. I tried going through in a step-by-step manner, but When I choose a RSS datasource in step 3, the step 4 popup box for the RSS source does not show up. The datasource is created in the page, but it says "Error Creating Control". When I look in the source, the RSSDataSource shows an error "Element 'RssDataSource' is not a known element..." Did I miss something?

  • Hi Nilesh,

    I'm wondering whether the control wasn't properly installed for some reason. Can you post this question to Dmitry over on his blog? http://blogs.msdn.com/dmitryr -- he should be able to help.

    Thanks,

    Scott

  • This is really interesting, but while reading it, the thought occurs to me that if you create a strongly typed class for a specific RSS feed, and then the publisher decideds to update the feed to include some fancy new feature, doesn't it break the app? Wouldn't this be a case where strong typing is not a good idea?

  • Hi Mike,

    I believe the way Dmitry implements the handler above it only parses on demand, and fails gracefully. That way if the schema for a property you aren't using changes, you should be fine.

    Of course, if you depend on a particular property element that is no longer there, you'll have problems regardless of whether it is strongly typed or late bound.

    Hope this helps,

    Scott

  • This is awesome, now I am free from third party vendors.

  • March 26th, 2006 Update: Dmitry just updated the (origional) original download here.

  • I get this error: DataBinding: 'RssToolkit.RssElementCustomTypeDescriptor' does not allow indexed access.

    on this line:
    <asp:Label ID="content_encodedLabel" runat="server" Text=''>

    is there something i have missed?

  • Hi Mikael,

    Can you send me a sample .zip file over email to look at?

    Thanks,

    Scott

  • I had the same problem. I then removed the fields that are related to the comments (commentslabel...) and then it worked. I guess that the original entries have proper indices but the comments don't.

  • Hello,

    I need to have 2 versions of a RSS file for two different cultures.

    For that reason I set .NavigateUrl = "~/News.ashx?Culture=" & System.Threading.Thread.CurrentThread.CurrentCulture.ToString()

    I get an error:
    '~/News.ashx?Culture=pt-PT' is not a valid virtual path.

    My objective was to have the culture info in my ashx file so I could generate the right RSS file from a database.

    Any idea of how to do this?

    Thanks,
    Miguel

  • Hi Miguel,

    Can you try removing the "~" from the URL? I'm wondering if that is causing the problem.

    thanks,

    Scott

  • Scott,

    I see this in your tutorial:

    "to consume remote RSS feeds the hosted server will need to allow remote out-bound http requests"

    can you tell me how to enable this on the server? I'm using IIS 5.x.

  • Hi Vue,

    You'll need to make sure that the proxy configuration for the web-server is setup correctly if you are within an Intranet environment.

    This article discusses how to configure this more: http://support.microsoft.com/default.aspx?scid=kb;en-us;318140

    Hope this helps,

    Scott

  • Scott,

    Our server does not use Proxy. How will this be different?

  • Hi Vue,

    What is the error you are seeing?

    Thanks,

    Scott

  • Scott,

    I have tried several RSS Readers. For general Readers, I get these errors:
    "The Remote Server returned an error. (401) Unauthorized"

    "The RSS Channel is not valid..."

    However, if I used a reader that allows for secured login (for example, allows the user to enter LAN ID and password, then it works. I sometimes get a "No Links found" message.

    in my web.config file, I have this















    So, basically, allow only authenticated users to the intranet, but let everyone else access the "rssfeeds" directory.

  • I was wondering if anyone had any success with adding additional namespaces when publishing a feed?

    I tried modifying app_code/Sample5.rss with a new namespace declaration and the new prefixed rss elements, but when i viewed the feed using Scenario5.ashx the declaration and prefixes disppeared. The new rss elements showed up, but without the prefix. The declaration was completed removed from the tag.

    Any advice on how to implement would be greatly appreciated.

  • Hi Jeff,

    I'd recommend posting this question again on Dmitry's blog: http://blogs.msdn.com/dmitryr/

    He wrote the RSS toolkit and would be happy to help I'm sure.

    Thanks,

    Scott

  • I want to ask my problem which was i faced using Rss toolkit.

    I want to publish my articles which are come from database according to category .

    I generate .ashx file also , but i am unable to use that .ashx file.
    plz,someone help me..

  • Hi Sam,

    Can you send me email (scottgu@microsoft.com) with more details of the issue? I will then loop you in with Dmitry who wrote the RSS Toolkit.

    Thanks,

    Scott

  • Excellent tool - made my external news section cake!

  • very help thanks all lot

  • This code is great. Has been a huge help. I have just what i want running locally. Then I upload the site to a Godaddy hosted site and everything times out. Is this a proxy issue? I'm going to get any help from Godaddy. Is there another hosting provider someone could recommend?

    Thanks!!!!

  • Hi Scott, your blog is awesome. It saved my life last month when I was working with some membership api stuff, and your reply to my post then was very helpful.

    I'm in the early stages of developing an aggregator for our users. We could have hundreds of user, each with 10s or 100s of feeds. Would Dmitryr's tool scale for something like this? It doesn't make sense to use the rssdl.exe for generating the classes and I'm not sure if it makes sense to somehow dynamically add all those feeds to the app_code directory either. I think that leaves using the RSSDataSource. Should I create a datasource for each feed a user may have? Or iterate the list of feeds, assigning each one in turn to the datasource?

    Again, thanks for a great and very useful blog.

  • Hi Troy,

    Very interesting question. For this scenario I'd probably recommend storing the feed information directly within a database, and use that to be able to construct a unique set of feeds out of all the ones registered. I'd then have a background process (implemented as a console application) on the server wake up periodically and check the feeds one after another for updates. Any updates would be persisted into the database - which the web application could then display back to the users.

    I think this type of model would scale very well.

    Hope this helps,

    Scott

  • Hi MickyR,

    It could be a proxy issue. Can you check with GoDaddy to see whether they allow remote network connections from their servers? If they do, they might have a proxy setting for you to set in your web.config file.

    Thanks,

    Scott

  • Are we still stuck on this index bug?
    It's been a year now~~~

  • Hi Charles,

    Which index bug are you referring to?

    Thanks,

    Scott

Comments have been disabled for this content.