SyndicationFeed不添加rel =“自我”属性
问题描述:
我使用SyndicationFeed
生成Atom提要。SyndicationFeed不添加rel =“自我”属性
除了当我使用W3C Feed Validation Service验证我的提要时,我似乎有所有工作,我收到以下警告。
此供稿是有效的,但通过实施以下建议可以改善与最广泛的供稿阅读器的互操作性。 行2,列0:缺少原子:链接使用rel =“自我”
这是很容易添加到我创建了一个标签的属性,但我怎么能得到SyndicationFeed
增加吗?我没有看到这个设置。
这是我的供稿的第一部分。
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us">
<title type="text">Insider Articles</title>
<subtitle type="text">Insider Articles data feed.</subtitle>
<id>http://www.insiderarticles.com/Syndication/Atom</id>
<rights type="text">Copyright (c) 2016 Insider Articles. All Rights Reserved.</rights>
<updated>2016-10-02T12:47:21-07:00</updated>
<logo>http://www.insiderarticles.com/Content/Images/rss.jpg</logo>
<link rel="alternate" href="http://www.insiderarticles.com/" />
<entry>
<!-- Etc... -->
下面是我构建饲料(减去饲料项目)的方式。
// Construct feed
SyndicationFeed feed = new SyndicationFeed(
Properties.Settings.Default.ApplicationName,
Properties.Settings.Default.FeedSummary,
new Uri(Properties.Settings.Default.ApplicationDomainRoot),
string.Format("{0}/Syndication/Atom", Properties.Settings.Default.ApplicationDomainRoot),
DateTime.Now);
feed.Language = "en-us";
feed.Copyright = new TextSyndicationContent(Properties.Settings.Default.ApplicationCopyright);
feed.ImageUrl = new Uri(string.Format("{0}/Content/Images/rss.jpg", uriRoot));
feed.Items = items;
答
尽管上述我的代码添加一个备用链路(rel="alternate"
),验证器还希望原始进料的链接以及(rel="self"
)。
因此,添加以下代码修复了问题。
string feedUrl = string.Format("{0}/Syndication/Atom", UrlBuilder.GetUriRoot(uri));
// Add feed (self) URL
var link = new SyndicationLink(new Uri(feedUrl));
link.RelationshipType = "self";
feed.Links.Add(link);