We have multiple RSS feeds in Tridion-based .NET websites. The RSS feeds need to be rendered as utf-8 (for content syndications). However, currently, they are rendered as urf-16 in the PROD environment.
Sample URLs: https://www.apa.org/news/apa/rss.xml https://www.apaservices.org/practice/clinic/covid-19-resources-rss.xml
If you view the page source in the browser, you will see the encoding is utf-16.
Most feeds are rendered based on broker query results. In some cases, the feed items are managed via a component in CMS. In all environments, the templates/TBBs and web applications are identical except for environment variables such as DB connection strings in web.config. The "preview" (stage) and "www" (live) sites are supported by the same CMS in PROD.
Currently, all feeds rendered via DXA web applications in DEV, QA and Preview show utf-8. But they all show utf-16 in the live sites.
FYI, the feeds in PROD also show urf-8 when debugging in Visual Studio using the localhost. We have Tridion Sites version 9.0 and DXA 2.1.
Update from Ahmad:
To make things clear. Let me show you sample code similar to our RSS feeds implementation:
public SyndicationFeed Feed { get; set; }
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "application/xml";
context.HttpContext.Response.ContentEncoding = Encoding.UTF8;
var rssFormatter = Feed.GetRss20Formatter();
rssFormatter.SerializeExtensionsAsAtom = false;
var xmlDoc = new XmlDocument();
using (var writer = XmlWriter.Create(xmlDoc.CreateNavigator().AppendChild()))
{
rssFormatter.WriteTo(writer);
}
//
// A few lines of code for some nodes custom implementation
//
using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
{
xmlDoc.WriteTo(writer);
}
}
Above code is written in a class (say RssActionResult) that inheriting from ActionResult class and being used in application PageController.