简体   繁体   中英

SyndicationFeed not adding rel=“self” attribute

I'm using SyndicationFeed to generate an Atom feed.

I seem to have everything working except when I use W3C Feed Validation Service to validate my feed, I get the following warning.

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations. line 2, column 0: Missing atom:link with rel="self"

It's easy enough to add an attribute to a tag that I created, but how can I get SyndicationFeed to add it? I'm not seeing a setting for this.

Here is the first part of my feed.

<?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... -->

Here's how I'm constructing my feed (minus the feed items).

// 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;

Although my code above adds an alternate link ( rel="alternate" ), the validator also wants a link to the original feed as well ( rel="self" ).

So adding the following code fixed the issue.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM