Awesome ASP.NET 2.0 RSS Tool-Kit Released
page 4 of 8
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 34183/ 58

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:

Listing 4

<?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:

Listing 5

<%@ 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:

Figure 8

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).


View Entire Article

User Comments

Title: Jeff Paul Scam   
Name: Jeff Paul Scam
Date: 2009-03-04 8:28:42 PM
Comment:
This post gave us a major Brainstorm session of all the possibilities we can utilize on our blog.
Title: How to download the updated feeds?   
Name: Abhilash
Date: 2009-02-26 4:06:39 AM
Comment:
Hi,
Article was nice. I must say.

Do you missed something additional?I mean...how we download the updated feeds only?

Is such a feature missing in it ?

Looking forward for your response.
Thankz.
Title: Any VB   
Name: Stephanie
Date: 2008-05-21 10:20:24 AM
Comment:
I am looking for a VB version

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 3:58:10 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search