fixed rss xml encoding always being utf-16
This commit is contained in:
parent
4e521145dd
commit
38e58f7b71
|
@ -13,6 +13,7 @@ public class SyndicationFeedFormatter : TextOutputFormatter {
|
||||||
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/atom+xml"));
|
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/atom+xml"));
|
||||||
|
|
||||||
SupportedEncodings.Add(Encoding.UTF8);
|
SupportedEncodings.Add(Encoding.UTF8);
|
||||||
|
SupportedEncodings.Add(Encoding.Unicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool CanWriteType(Type? type)
|
protected override bool CanWriteType(Type? type)
|
||||||
|
@ -23,10 +24,10 @@ protected override bool CanWriteType(Type? type)
|
||||||
httpContext.Response.Headers.ContentDisposition = "inline";
|
httpContext.Response.Headers.ContentDisposition = "inline";
|
||||||
|
|
||||||
var feed = context.Object as SyndicationFeed;
|
var feed = context.Object as SyndicationFeed;
|
||||||
|
|
||||||
await using var stringWriter = new StringWriter();
|
await using var stream = new MemoryStream();
|
||||||
await using var rssWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings {
|
await using var rssWriter = XmlWriter.Create(stream, new XmlWriterSettings {
|
||||||
Async = true
|
Async = true, Encoding = selectedEncoding
|
||||||
});
|
});
|
||||||
System.ServiceModel.Syndication.SyndicationFeedFormatter formatter;
|
System.ServiceModel.Syndication.SyndicationFeedFormatter formatter;
|
||||||
if (context.ContentType.Value?.StartsWith("application/rss+xml") is true) {
|
if (context.ContentType.Value?.StartsWith("application/rss+xml") is true) {
|
||||||
|
@ -41,6 +42,6 @@ protected override bool CanWriteType(Type? type)
|
||||||
formatter.WriteTo(rssWriter);
|
formatter.WriteTo(rssWriter);
|
||||||
rssWriter.Close();
|
rssWriter.Close();
|
||||||
|
|
||||||
await httpContext.Response.WriteAsync(stringWriter.ToString(), selectedEncoding);
|
await httpContext.Response.BodyWriter.WriteAsync(stream.ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue