Creating a dynamic RSS feed page in ASP.NET (C #) - do I need to do something extra?

I want to create a dynamic RSS feed to represent the contents of my site. I currently have an XML file in which each master record has data for the location, date and summary of the file. If I were to create this feed in ASP.NET, would I need to do something extra in terms of other things besides just parsing the XML and displaying some RSS? For example, how can I create an ASP.NET page with a different extension, for example a standard RSS file extension?

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

+4
source share
3 answers

Try creating your own HTTPHandler. Add the custom extension of this handler to web.config, and then add it to IIS so that it can be served by IIS.

This HTTPHandler will do RSS processing from XML and can write the output for your response.

This may be useful: http://msdn.microsoft.com/en-us/library/ms972953.aspx

+3
source

If you use .Net Framework 3.5, there is a great opportunity to generate RSS and Atom. Check the following MSDN page.

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

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

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

Or using some .NET tool like RSS.NET.

http://www.rssdotnet.com/

To process your own extension and create RSS, you need to create an HttpHandler and add the extension to 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(); } } } 

This is just a sample, and you need to set some feed settings.

+5
source

Should it really be an RSS extension? Why not an ASPX extension if it is ASP.NET?

Here is a good recommendation for feed output, just loop your XML (instead of SQL in this example), and you should be fine.

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

+1
source

All Articles