代码之家  ›  专栏  ›  技术社区  ›  George2

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

  •  1
  • George2  · 技术社区  · 16 年前

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

    2 回复  |  直到 9 年前
        1
  •  5
  •   Pavel Nikolov    16 年前

    我建议你用新的 Syndication API 这是.NET3.5附带的。下面是一个例子 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);
        }
    }
    
        2
  •  1
  •   Zafer    16 年前

    有一个开源的.net类库叫做RSS.Net. 看到了吗 http://www.rssdotnet.com/

    推荐文章