tags:

views:

780

answers:

3

I wish to create a dynamic RSS feed to represent my site's content. Currently, I have an XML file where each main entry has data for location, date, and summary of a file. If I were to create this feed in ASP.NET, would I need to do anything extra, in terms of things other than just parsing the XML and outputting some RSS? For example, how would I be able to create an ASP.NET page with a different extension, such as the standard RSS file extension?

In other words, let's say I can obtain the proper RSS code and output it through Response.Write. How do I make sure that it still functions as a ASP.NET application, though with the standard RSS file extension?

+1  A: 

Does it really have to be an RSS extension ? Why not a ASPX extension if it's ASP.NET ?

Here is a good guideline to output the feed, just loop through your XML (instead of the SQL in this example) and you should be alright.

http://www.geekpedia.com/tutorial157_Create-an-RSS-feed-using-ASP.NET-2.0.html

Amadeus45
+2  A: 

Try making a Custom HTTPHandler. Add a custom extension to this handler in web.config and then add this to IIS so that this can be served by IIS.

This HTTPHandler will do the RSS processing from XML and can write the output to your reponse.

This might be of help: http://msdn.microsoft.com/en-us/library/ms972953.aspx

Beginner
+4  A: 

If you are using .Net Framework 3.5, there is a great facility to generate RSS and Atom. Check the following MSDN page out.

http://msdn.microsoft.com/en-us/library/system.servicemodel.syndication.syndicationfeed.aspx

Or you can create it manually which you must implement the RSS specification.

http://cyber.law.harvard.edu/rss/rss.html

Or using some .NET Tool such as RSS.NET.

http://www.rssdotnet.com/

For handling your own extension and generating RSS, you have to create an HttpHandler and add the extension in the IIS application mapping.

using System;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Web;
using System.Xml;
using System.Xml.Linq;

public class RSSHandler : IHttpHandler
{

    public bool IsReusable
    {
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        XDocument xdoc = XDocument.Load("Xml file name");

        SyndicationFeed feed = new SyndicationFeed(from e in xdoc.Root.Elements("Element name")
                                                   select new SyndicationItem(
                                                       (string)e.Attribute("title"),
                                                       (string)e.Attribute("content"),
                                                       new Uri((string)e.Attribute("url"))));

        context.Response.ContentType = "application/rss+xml";

        using (XmlWriter writer = XmlWriter.Create(context.Response.Output))
        {
            feed.SaveAsRss20(writer);
            writer.Flush();
        }
    }

}

It's only a sample and you have to set some another settings of feed.

Mehdi Golchin