You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Sitemap genereator may still generate a sitemap with utf-16 encoding specified in the xml declaration because it uses XmlTextWriter to generate the xml which retrieves the encoding from the environment settings and will overwrite the content encoding declared in the XDocument.
I had to create a custom ActionResult using StringWriter rather than XmlTextWriter:
public class Utf8StringWriter : StringWriter
{
public override Encoding Encoding
{
get { return new UTF8Encoding(false); }
}
}
public class Utf8SitemapResult : ActionResult
{
private readonly IEnumerable<ISitemapItem> items;
private readonly ISitemapGenerator generator;
public Utf8SitemapResult(IEnumerable<ISitemapItem> items) : this(items, new SitemapGenerator())
{
}
public Utf8SitemapResult(IEnumerable<ISitemapItem> items, ISitemapGenerator generator)
{
Ensure.Argument.NotNull(items, "items");
Ensure.Argument.NotNull(generator, "generator");
this.items = items;
this.generator = generator;
}
public override void ExecuteResult(ControllerContext context)
{
var response = context.HttpContext.Response;
response.ContentType = "text/xml";
response.ContentEncoding = Encoding.UTF8;
using (var writer = new Utf8StringWriter())
{
var doc = generator.GenerateSiteMap(items);
doc.Save(writer, SaveOptions.None);
response.Write(writer);
}
}
}
The text was updated successfully, but these errors were encountered:
The Sitemap genereator may still generate a sitemap with utf-16 encoding specified in the xml declaration because it uses XmlTextWriter to generate the xml which retrieves the encoding from the environment settings and will overwrite the content encoding declared in the XDocument.
I had to create a custom ActionResult using StringWriter rather than XmlTextWriter:
The text was updated successfully, but these errors were encountered: