In this article I will explain with an example, how to fetch and display RSS Feeds in ASP.Net Core MVC.
This article covers how to fetch RSS Feeds from a URL and display it on the Website in ASP.Net Core MVC.
Note: For beginners in ASP.Net Core 7, please refer my article ASP.Net Core 7: Hello World Tutorial with Sample Program example.
 
 

The RSS Feeds returned from the API

The following RSS Feeds are used in this article.
Fetch and Display RSS Feeds in ASP.Net Core
 
 

Model

The Model class consists of following properties which will be used for deserialization of XML data.
[XmlType("rss")]
public class RssModel
{
    [XmlElement("channel")]
    public Channel Channel { getset; }
}
 
[XmlType("channel")]
public class Channel
{
    [XmlElement("item")]
    public List<Item> Items { getset; }
}
 
public class Item
{
    [XmlElement("title")]
    public string Title { getset; }
 
    [XmlElement("description")]
    public string Description { getset; }
 
    [XmlElement("link")]
    public string Link { getset; }
 
    [XmlElement("pubDate")]
    public string PublishedDate { getset; }
}
 
 

Namespaces

You will need to import the following namespaces.
using System.Net;
using System.Xml;
using System.Xml.Serialization;
 
 

Controller

The Controller consists of following Action method.
Action method for handling GET operation
Inside this Action method, first the Security Protocol is set.
Note: For more information on using TLS 1.2 with HttpClient, please refer my article Using TLS1.2 with HttpClient in C# and VB.Net and for previous .Net Framework versions, please refer Using TLS1.2 in .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0.
 
Then, the RSS Feeds API is called using HttpClient class and the response is received using GetAsync method of HttpResponseMessage class.
If the response is true then, XML string is downloaded using ReadAsStringAsync method of StringReader class.
Then, an object of XmlReader class is created using Create method of XmlReader class.
The XML string is deserialized into RssModel class using Deserialize method of the XmlSerializer class object.
Finally, the RssModel class is returned to the View.
public class HomeController : Controller
{
    public IActionResult Index()
    {
        //Setting TLS 1.2 protocol.
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
 
        HttpClient client = new HttpClient();
        HttpResponseMessage response = client.GetAsync("https://asp-umbraco.azurewebsites.net/rss/content").Result;
        if (response.IsSuccessStatusCode)
        {
            using (StringReader stream = new StringReader(response.Content.ReadAsStringAsync().Result))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(RssModel));
                    RssModel rss = (RssModel)serializer.Deserialize(reader);
                    return View(rss);
                }
            }
        }
 
        return View();
    }
}
 
 

View

Inside the View, in the very first line the RssModel class is declared as model for the View.
The View consists of Anchor tag for displaying the RSS Feeds links.
A FOR EACH loop is executed over the Item class of RssModel and RSS Feeds and HTML Table will be used to display the RSS Feeds contents i.e. Link, Title and Description.
The href property of the Anchor tag is set to Link.
@model RssModel
@using Display_RSS_Feeds_Core_MVC.Models
@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    @foreach (Item item in Model.Channel.Items)
    {
        <table width="100%">
            <tr>
                <td><a id="lnkTitle" href="@item.Link">@item.Title</a></td>
            </tr>
            <tr>
                <td>@item.Description</td>
            </tr>
        </table>
        <br />
    }
</body>
</html>
 
 

Screenshot

Fetch and Display RSS Feeds in ASP.Net Core
 
 

Demo

 
 

Downloads