如何将RSS功能添加到我的网站?

时间:2010-09-03 10:56:26

标签: c# asp.net .net visual-studio-2008 rss

我正在使用VS2008 + C#+ .Net 3.5 + IIS 7.0 + ASP.Net来开发一个简单的Web应用程序。我想在我的网站的某些页面添加RSS功能,以便人们可以使用他们流行的RSS阅读器来接收内容更新的通知。

在我的开发环境中执行此操作的任何简单方法?我只需要非常基本的RSS功能。

2 个答案:

答案 0 :(得分:5)

我建议你使用.NET 3.5附带的新Syndication API。以下是MSDN How to: Create a Basic RSS Feed article

的示例
public class BlogService : IBlog
{
    public Rss20FeedFormatter GetBlog()
    {
        SyndicationFeed feed = new SyndicationFeed("My Blog Feed", "This is a test feed", new Uri("http://SomeURI"));
        feed.Authors.Add(new SyndicationPerson("someone@microsoft.com"));
        feed.Categories.Add(new SyndicationCategory("How To Sample Code"));
        feed.Description = new TextSyndicationContent("This is a how to sample that demonstrates how to expose a feed using RSS with WCF");

        SyndicationItem item1 = new SyndicationItem(
            "Item One",
            "This is the content for item one",
            new Uri("http://localhost/Content/One"),
            "ItemOneID",
            DateTime.Now);

        SyndicationItem item2 = new SyndicationItem(
            "Item Two",
            "This is the content for item two",
            new Uri("http://localhost/Content/Two"),
            "ItemTwoID",
            DateTime.Now);

        SyndicationItem item3 = new SyndicationItem(
            "Item Three",
            "This is the content for item three",
            new Uri("http://localhost/Content/three"),
            "ItemThreeID",
            DateTime.Now);

        List<SyndicationItem> items = new List<SyndicationItem>();

        items.Add(item1);
        items.Add(item2);
        items.Add(item3);

        feed.Items = items;

        return new Rss20FeedFormatter(feed);
    }
}

答案 1 :(得分:1)

有一个名为RSS.Net的开源.net类库。见http://www.rssdotnet.com/