Created
October 11, 2012 23:22
-
-
Save jakejscott/3876267 to your computer and use it in GitHub Desktop.
FeedResult RSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FeedResult : ActionResult | |
{ | |
public Encoding ContentEncoding { get; set; } | |
public string ContentType { get; set; } | |
private readonly SyndicationFeedFormatter feed; | |
public SyndicationFeedFormatter Feed | |
{ | |
get { return feed; } | |
} | |
public FeedResult(SyndicationFeedFormatter feed) | |
{ | |
this.feed = feed; | |
} | |
public override void ExecuteResult(ControllerContext context) { | |
if (context == null) | |
{ | |
throw new ArgumentNullException("context"); | |
} | |
HttpResponseBase response = context.HttpContext.Response; | |
response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/rss+xml"; | |
if (ContentEncoding != null) | |
{ | |
response.ContentEncoding = ContentEncoding; | |
} | |
if (feed != null) | |
{ | |
using (var xmlWriter = new XmlTextWriter(response.Output)) | |
{ | |
xmlWriter.Formatting = Formatting.Indented; | |
feed.WriteTo(xmlWriter); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment