Fix sitemap XML: UTF-8 encoding, correct namespace, and element order by mt0321 · Pull Request #1636 · YAFNET/YAFNET · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions yafsrc/YAFNET.Types/Constants/UrlLocation.cs
2 changes: 1 addition & 1 deletion yafsrc/YAFNET.Types/Objects/Sitemap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace YAF.Types.Objects;
/// <summary>
/// The site Map. XML
/// </summary>
[XmlRoot("urlset", Namespace = "https://www.sitemaps.org/schemas/sitemap/0.9")]
[XmlRoot("urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
public class SiteMap
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace YAF.Pages;

using System.Globalization;
using System.IO;
using System.Net.Mime;
using System.Text;
using System.Xml.Serialization;

using Core.Model;
Expand Down Expand Up @@ -85,13 +87,14 @@ public IActionResult OnGet()

var xmlSerializer = new XmlSerializer(typeof(SiteMap));

using var textWriter = new StringWriter();
xmlSerializer.Serialize(textWriter, siteMap);
using var writer = new Utf8StringWriter();
xmlSerializer.Serialize(writer, siteMap);

return new ContentResult {
ContentType = "application/xml",
Content = textWriter.ToString(),
StatusCode = 200
};
return this.Content(writer.ToString(), MediaTypeNames.Application.Xml, Encoding.UTF8);
}

private sealed class Utf8StringWriter : StringWriter
{
public override Encoding Encoding => Encoding.UTF8;
}
}
19 changes: 11 additions & 8 deletions yafsrc/YetAnotherForum.NET/Pages/SiteMap.cshtml.cs