Skip to content

Commit

Permalink
Outputting XML from an API controller has changed a bit from ASP.NET …
Browse files Browse the repository at this point in the history
…to ASP.NET Core
  • Loading branch information
abjerner committed Jan 6, 2022
1 parent 054aaa0 commit 8e4c81c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/Limbo.Umbraco.Seo/Sitemaps/SitemapController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Text;
using Umbraco.Cms.Web.Common.Controllers;

namespace Limbo.Umbraco.Seo.Sitemaps {
Expand All @@ -13,8 +14,25 @@ public SitemapController(ISitemapHelper sitemapHelper) {
}

[HttpGet]
public HttpResponseMessage XmlSitemap() {
return _sitemapHelper.BuildSitemap(HttpContext).AsResponseMessage();
public ActionResult XmlSitemap() {

// Generate a new sitemap
ISitemapResult sitemap = _sitemapHelper.BuildSitemap(HttpContext);

// Generate the XML for the sitemap
StringBuilder builder = new StringBuilder();
using (TextWriter writer = new StringWriter(builder)) {
sitemap.ToXml().Save(writer);
}

// Return a content result with the XML
return new ContentResult {
ContentType = "application/xml",
Content = builder.ToString(),
StatusCode = 200
};


}

}
Expand Down

0 comments on commit 8e4c81c

Please sign in to comment.