Rss20FeedFormatter is producing RSS that is not well formed
-
25-09-2019 - |
문제
I am using ASP.Net MVC2 and have a RSS feed for my blog. I am using out of the box functionality in System.ServiceModel.Syndication and Rss20FeedFormatter.
The feed works fine and can be read by Outlook as well as every browser I have tried. However when I submitted the RSS feed to google as a sitemap I got validation errors.
Out of curiosity I validated the feed with feedvalidator which reported similar issues.
Feed: http://www.chrispfarrell.com/Blog/Rss
If you pop this feed in at feedvalidator.org you will see the problems.
There is really no custom code going on to generate the RSS.
The controller action is
public FeedResult Rss()
{
const string baseUrl = "http://www.chrispfarrell.com/Blog/View/";
var blogs = _blogService.GetBlogs();
var feed = new SyndicationFeed
{
Title = new TextSyndicationContent("Chris Farrell"),
Copyright = new TextSyndicationContent("Copywrite Chris Farrell 2010")
};
var postItems = blogs.Take(25)
.Select(p => new SyndicationItem(p.Title,p.Body,new Uri(baseUrl + p.BlogUrl))
{
PublishDate = p.DateCreated,
});
feed.Items = postItems;
return new FeedResult(new Rss20FeedFormatter(feed));
}
Any comments as to why the feed would not be valid and well formed? I can post the code for FeedResult if needed but its pretty standard code.
Thanks
Chris Farrell
해결책
The Feed was missing the <link> element in the root <channel> element.
Rather than using an object initializer, I am using one of the constructors now which accepts 3 arguments(feed title, description and feed alternate link). The third argument for feed alternate link renders in the root channel <link> tag which makes the feed now valid.