RSS Feed Integration for ASP.NET Core based Kentico Xperience 13.0 applications using Content Tree Routing
This package is compatible with ASP.NET Core 3.1+ and is designed to be used with ASP.NET Core applications integrated with Kentico Xperience 13.0.
-
Import the Page Type definition included in this repository, for the version of the package your are installing, into your Administration application:
Example: ./src/XperienceCommunity.RSSFeeds.Import.v1.0.0.zip
-
Install the NuGet package in your ASP.NET Core project
dotnet add package XperienceCommunity.RSSFeeds
-
Register the package's types with the
IServiceCollectionpublic class Startup { public void ConfigureServices(IServiceCollection services) { services.AddRSSFeeds(); } }
-
Create a new Page (anywhere) in the Content Tree for your RSS Feed and populate the required fields:
-
Optional: Create your own custom
IRSSFeedItemsRetrieverimplementation:public class CustomRSSFeedItemsRetriever : IRSSFeedItemsRetriever { // ... public async Task<ICollection<Item>> RetrieveAsync(RSSFeedPage feedPage, CancellationToken token) { // ... } }
Then register it with the
IServicesCollection:public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddRSSFeeds<CustomRSSFeedItemsRetriever>(); } }
Kentico Xperience handles routing for the RSS feed using Content Tree Routing.
This library provides a Controller and Page Type to connect the Content Tree Route to a dynamically generated RSS Feed.
You can create as many RSS Feed Pages as you need and select different Page Types for each of them if you want to host feeds for different content. The URL of the RSS Feed Page is the URL of the RSS Feed.
It also provides a default implementation of IRSSFeedItemsRetriever which uses the DocumentPageTitle, DocumentPageDescription and DocumentPageKeywords fields of retrieved pages to populate the RSS Feed.
The benefit of using these fields is that no SQL UNIONs need performed to get all the necessary data if multiple Page Types are specified for the RSS Feed.
Below is an example of this metadata populated for a Page:
And the resulting RSS Feed:
If the RSSFeedController is called from outside Xperience's routing or if the RSS Feed Page has no selected Page Types, the URL will return a 404.
Populating the TreeNode fields used by this package can be additional work for Content Managers, especially when
the values they want in these fields already exist in the Page Type custom fields for each Page Type.
Fortunately this can be easily resolved by using Document Global Events in a custom Module class:
[assembly: RegisterModule(typeof(TreeNodeEventsModule))]
namespace CMSApp
{
public class TreeNodeEventsModule : Module
{
public TreeNodeEventsModule() : base(nameof(TreeNodeEventsModule)) { }
protected override void OnInit()
{
base.OnInit();
DocumentEvents.Insert.Before += Insert_Before;
DocumentEvents.Update.Before += Update_Before;
}
private void Update_Before(object sender, DocumentEventArgs e)
{
e.Node.SetValue("DocumentPageTitle", ...);
e.Node.SetValue("DocumentPageDescription", ...);
e.Node.SetValue("DocumentPageKeywords", ...);
}
private void Insert_Before(object sender, DocumentEventArgs e)
{
e.Node.SetValue("DocumentPageTitle", ...);
e.Node.SetValue("DocumentPageDescription", ...);
e.Node.SetValue("DocumentPageKeywords", ...);
}
}
}If you need to populate more of the fields for the RSS Feed Items (like Author), use something other than DocumentLastPublished to order the results populating the Feed, or populate the Feed items from specific database columns, then implement your own IRSSFeedItemsRetriever using whatever DocumentQuery fits your needs.
You can also use the RSSFeedPage parameter to populate different content for the same Page Types in different parts of the Content Tree.
If you discover a problem, please open an issue.
If you would like contribute to the code or documentation, please open a pull request.