SyndicationFeedResult 源代码

原文地址:http://code.google.com/p/netfx/source/browse/trunk/Source/Web/Mvc/SyndicationFeedResult.cs?r=73

/* 
 * Dependencies: 
 *              System.Web.Abstractions
 *              System.Web.Mvc
 *              System.Web.Routing
 *              System.ServiceModel.Web
 * Authors: Juan Wajnerman - jwajnerman@manas.com.ar
 */

using System.ServiceModel.Syndication;
using System.Xml;

namespace System.Web.Mvc
{
        public class SyndicationFeedResult : ActionResult
        {
                SyndicationFeed feed;
                string format;

                public SyndicationFeedResult(SyndicationFeed feed, string format)
                {
                        this.feed = feed;
                        this.format = format;
                }

                public SyndicationFeedResult(SyndicationFeed feed)
                        : this(feed, "atom")
                {
                }

                public override void ExecuteResult(ControllerContext context)
                {
                        context.HttpContext.Response.ContentType = "text/xml";
                        SyndicationFeedFormatter f = format == "atom" ?
                                        (SyndicationFeedFormatter)new Atom10FeedFormatter(feed) :
                                        (SyndicationFeedFormatter)new Rss20FeedFormatter(feed);
                        using (var writer = XmlWriter.Create(context.HttpContext.Response.Output))
                                f.WriteTo(writer);
                }
        }
}

请参考:http://weblogs.asp.net/britchie/archive/2011/02/21/serving-up-rss-feed-in-mvc-using-wcf-syndication.aspx

posted on 2011-03-07 14:02  think8848  阅读(1281)  评论(1编辑  收藏  举报