【问题标题】:Render pubDate with RSS SyndicationFeed api使用 RSS SyndicationFeed api 渲染 pubDate
【发布时间】:2012-05-20 12:00:52
【问题描述】:

我正在尝试从我的 ASP.net MVC 站点提供 RSS 提要。 pubdate 元素的一切都在接受。我似乎无法让 Rss20FeedFormatter 输出它。我认为它映射到 SyndicationFeed 对象上的 LastUpdatedDate 属性,但输出为 LastBuildDate。

有谁知道我如何使用 SyndicationFeed 和 Rss20FeedFormatter 在我的 RssFeed 中呈现 pubDate 节点?

   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);
        }
    }

我如何创建提要的示例。

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

【问题讨论】:

    标签: c# asp.net-mvc rss syndicationfeed


    【解决方案1】:

    似乎对象模型目前仅支持项目上的 pubDate,而不是提要/频道上的。您可以将其添加为 ElementExtension:

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

    您只需要注意正确格式化日期,请看这里:DateTime to RFC-1123 gives inaccurate timezone

    【讨论】:

    • 谢谢,这正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-18
    • 2016-04-08
    • 2014-03-28
    相关资源
    最近更新 更多