Question

I am trying to serve an RSS feed from my ASP.net MVC site. Everything is working accept for the pubdate element. I can't seem to get the Rss20FeedFormatter to output it. I thought that it maps to the LastUpdatedDate property on the SyndicationFeed object, but that outputs as LastBuildDate.

Does anyone know how I can use the SyndicationFeed with Rss20FeedFormatter to render the pubDate node in my RssFeed?

   public class RssActionResult : ActionResult
    {
        public SyndicationFeed Feed { get; set; }
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.ContentType = "application/rss+xml";
            var rssFormatter = new Rss20FeedFormatter(Feed, false);
            using (var writer = XmlWriter.Create(context.HttpContext.Response.Output, new XmlWriterSettings{ Indent = true}))
                rssFormatter.WriteTo(writer);
        }
    }

example of how I am creating the feed.

new SyndicationFeed("Title", "Description", url, "test_id", publishDate, feedItems){ LastUpdatedTime = publishDate}
Was it helpful?

Solution

It seems that the object model currently supports pubDate only on items, not on the feed/channel. You can add it as an ElementExtension:

feed.ElementExtensions.Add("pubDate", "", DateTime.UtcNow.ToString("r"));

You just have to take care to format the date correctly, have a look here: DateTime to RFC-1123 gives inaccurate timezone

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top