9.2. Making an RSS Feed Available from Your Site

You can create an RSS feed by sending any list of data as an XML stream. The LINQ to XML capabilities in ASP.NET 3.5 make generating XML on the fly easy. Follow these steps to create an ASP.NET handler that produces an RSS feed:

  1. Add a generic handler named rsshandler.ashx to your project (FileNew FileGeneric HandlerAdd).

  2. Add the statement Imports System.Xml.Linq below Imports System.

  3. Replace the existing ProcessRequest() subroutine with the contents of Listing 9-1.

When you browse to rsshandler.ashx with Internet Explorer 7, the browser recognizes that it's RSS. IE 7 formats the content and makes it easy to subscribe to the feed (see Figure 9-1).

Figure 9-1. The RSS feed in Internet Explorer 7.
Listing 9-1. An RSS Feed Using LINQ to XML
Public Sub ProcessRequest _
(ByVal context As HttpContext) _
 Implements IHttpHandler.ProcessRequest
  Dim rssdoc As New XDocument(New XDeclaration("1.0", Nothing, Nothing))      →4
  rssdoc.Add(New XComment("XML to LINQ Generated RSS Feed"))                  →5 Dim rssrootelement As New XElement("rss", New XAttribute("version", ...

Get ASP.NET 3.5 For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.