我正在尝试提供来自我的ASP.net MVC站点的RSS feed。一切正常,接受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}发布于 2012-05-12 16:51:36
似乎对象模型目前只在项目上支持pubDate,而不是在提要/频道上。您可以将其添加为ElementExtension:
feed.ElementExtensions.Add("pubDate", "", DateTime.UtcNow.ToString("r"));你只需要注意正确地格式化日期,看看这里:DateTime to RFC-1123 gives inaccurate timezone
https://stackoverflow.com/questions/10558989
复制相似问题