using System.Xml; using System.Xml.Linq; using Microsoft.AspNetCore.Mvc; using Nop.Core.Rss; namespace Nop.Web.Framework.Mvc; /// /// RSS action result /// public partial class RssActionResult : ContentResult { /// /// Ctor /// /// Syndication feed /// Feed page url for atom self link public RssActionResult(RssFeed feed, string feedPageUrl) { ContentType = "application/atom+xml"; Feed = feed; //add atom namespace XNamespace atom = "http://www.w3.org/2005/Atom"; Feed.AttributeExtension = new KeyValuePair(new XmlQualifiedName("atom", XNamespace.Xmlns.NamespaceName), atom.NamespaceName); //add atom:link with rel='self' Feed.ElementExtensions.Add(new XElement(atom + "link", new XAttribute("href", new Uri(feedPageUrl)), new XAttribute("rel", "self"), new XAttribute("type", "application/rss+xml"))); } /// /// Feed /// public RssFeed Feed { get; set; } /// /// Execute result async /// /// ActionContext /// A task that represents the asynchronous operation public override Task ExecuteResultAsync(ActionContext context) { Content = Feed.GetContent(); return base.ExecuteResultAsync(context); } /// /// Execute result /// /// ActionContext public override void ExecuteResult(ActionContext context) { Content = Feed.GetContent(); base.ExecuteResult(context); } }