asp.net - .NET ServiceModel.Syndication - Changing Encoding on RSS Feed -


I am trying to solve a bug where all RSS feeds are being generated that generate the following error in Internet Explorer (Version 8 and 9):

Feed code error Encoding specified from the current encoding is not supported. Line: 1 character: 40

  & lt ;? XML version = "1.0" encoding = "UTF-16"? & Gt;    

The issue is that the actual encoding type to be sent through the actual headers declares the document. Feed the output looks like my code to write HTML:

  public contentResult Index () {var feed = _syndication.SyndicateIdeas (_repository.GetIdeas (0,15) .Ideas); Var sb = new stringbilder (); (Var Author = XmlWriter.Create (sb, New XmlWriterSettings {encoding = encoding. UTF8, Nulainhandling = New Lainshandling. Antaijet, newline Ontiws = true, indent = true})) {feed. SaveAsRss20 (author); Writer.Close (); } Return content (SB ToString (), "Application / RSS + xml", encoding. UTF8); }   

And here my code appears to actually create a feed, System.ServiceModel.Syndication In NET 4.0

  var feed = new Sindikfikeshn ( "Captain Obvio. - recent Aidiaj", "posted most recently considered by the community to captain Obviokss" new Uri ( "http: // captainobvio .us / ")," Captain Obivo. ", New Datetime Offset (Ideas [0]. DatePosted), items) {Generator =" Captain Obvios - http://captainobvio.us/ "}; Return feed;   

What I would like to do is to replace the YouTube document utf-8 instead of utf-16. I also checked the Encoding Namespace to see if the UTF was option 16 (so I could correct the HTTP header instead of the XML document) and was unable to find it.

Is there any easy way to change the encoding feature directly on the XML document from System.ServiceModel.Syndication? What is the easiest way to fix this problem?

Why this happens because you are strings Unicode manufacturer XmlWriter the Stringbilder nits, so XML-raters UTF -16 and you can not modify it.

Then you can use a stream instead of string builder, then you can control the encoding with the settings:

  var settings = new XmlWriterSettings {Encoding = Encoding.UTF8, NewLineHandling = NewLineHandling. Make sure, NewLineOnAttributes = true, indent = true}; (Var, Writer = XmlWriter.Create (Stream, Settings)) (Var Stream = New MemoryStream (). (Feeds Save ASRSS 20 (Author); writer.Flush (); Return File (stream. , "App / RSS + xml; Charset = UTF-8");}   

All this has been said to be a very good, more MVCish and I would suggest you a solution that it is a SyndicationResult to write:

  Public class syndication results: Proceedings [Private Readonly Syndication Feeds _feed; Vjnik syndication Result (Sindikfikeshn feed) {if (feed == null) {new Actiteepiaksship (401 "not found");} _feed = feed;} public override void ExecuteResult (controller reference model) {var settings = new XmlWriterSettings {encoding = encoding. UTF8, NewLineHandling = NewLineHandling.Entitize, NewLineOnAttributes = true, Indent = true}; Var response = reference. HttpContext.Response; Response.ContentType = "application / rss + xml; charset = utf-8"; (Var writer = XmlWriter.Create (using response.OutputStream, Settings) {_feed.SaveAsRss20 (author); }}}   

And just return this result to your controller action so that you do not dislodge your controller tasks with the plumbing code:

  public Performance Index () {Var thoughts = _repository.GetIdeas (0, 15) .Ideas; Var feed = _syndication.SyndicateIdeas (idea); Return a new syndication result (feed); }    

Comments