Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8540333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:34:25+00:00 2026-06-11T11:34:25+00:00

I’m looking for the best way to create an RSS feed via MVC4 (and/or

  • 0

I’m looking for the best way to create an RSS feed via MVC4 (and/or WebAPI). This post seemed the most applicable http://www.strathweb.com/2012/04/rss-atom-mediatypeformatter-for-asp-net-webapi/. But it was written in the pre-Release days of WebAPI. I’ve used Nuget to bring all packages up-to-date but attempting to build the project tosses:

Error   2   The type or namespace name 'FormatterContext' could not be found (are you missing a using directive or an assembly reference?)  G:\Code\MvcApplication-atomFormatter\MvcApplication-atomFormatter\SyndicationFeedFormatter.cs   38  129 MvcApplication_syndicationFeedFormatter

I’ve found a number of articles explaining that the MediaTypeFormatter has changed significantly since beta but I have found details on the adjustments required to the code snippet in question.

Is there an updated resource showing the construction of an RSSFormatter?

thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:34:26+00:00Added an answer on June 11, 2026 at 11:34 am

    Yes I wrote that tutorial against Beta.

    Below is the code updated to RTM version.

    One advice, if I may, is that this example uses a simple “whitelist” of concrete types for which RSS/Atom feed is build (in this case my Url model). Ideally in more complex scenarios, you’d have the formatter set up against an interface, rather than a concrete type, and have all Models which are supposed to be exposed as RSS to implement that interface.

    Hope this helps.

       public class SyndicationFeedFormatter : MediaTypeFormatter
        {
            private readonly string atom = "application/atom+xml";
            private readonly string rss = "application/rss+xml";
    
            public SyndicationFeedFormatter()
            {
                SupportedMediaTypes.Add(new MediaTypeHeaderValue(atom));
                SupportedMediaTypes.Add(new MediaTypeHeaderValue(rss));
            }
    
            Func<Type, bool> SupportedType = (type) =>
            {
                if (type == typeof(Url) || type == typeof(IEnumerable<Url>))
                    return true;
                else
                    return false;
            };
    
            public override bool CanReadType(Type type)
            {
                return SupportedType(type);
            }
    
            public override bool CanWriteType(Type type)
            {
                return SupportedType(type);
            }
    
            public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
            {
                return Task.Factory.StartNew(() =>
                {
                    if (type == typeof(Url) || type == typeof(IEnumerable<Url>))
                        BuildSyndicationFeed(value, writeStream, content.Headers.ContentType.MediaType);
                });
            }
    
            private void BuildSyndicationFeed(object models, Stream stream, string contenttype)
            {
                List<SyndicationItem> items = new List<SyndicationItem>();
                var feed = new SyndicationFeed()
                {
                    Title = new TextSyndicationContent("My Feed")
                };
    
                if (models is IEnumerable<Url>)
                {
                    var enumerator = ((IEnumerable<Url>)models).GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        items.Add(BuildSyndicationItem(enumerator.Current));
                    }
                }
                else
                {
                    items.Add(BuildSyndicationItem((Url)models));
                }
    
                feed.Items = items;
    
                using (XmlWriter writer = XmlWriter.Create(stream))
                {
                    if (string.Equals(contenttype, atom))
                    {
                        Atom10FeedFormatter atomformatter = new Atom10FeedFormatter(feed);
                        atomformatter.WriteTo(writer);
                    }
                    else
                    {
                        Rss20FeedFormatter rssformatter = new Rss20FeedFormatter(feed);
                        rssformatter.WriteTo(writer);
                    }
                }
            }
    
            private SyndicationItem BuildSyndicationItem(Url u)
            {
                var item = new SyndicationItem()
                {
                    Title = new TextSyndicationContent(u.Title),
                    BaseUri = new Uri(u.Address),
                    LastUpdatedTime = u.CreatedAt,
                    Content = new TextSyndicationContent(u.Description)
                };
                item.Authors.Add(new SyndicationPerson() { Name = u.CreatedBy });
                return item;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.