Controllers with ".xml" in the route template - Umbraco 14
I'm running into an issue where I'd like to provide XML sitemap using a controller. The sitemap may or may not include paginated results so keeping it dynamically produced within a number of controller endpoints is ideal. While I am trying to use SimpleMvcSitemp.Core to handle this, I'm running into one issue.
When my route template ends in .xml, the data from any documents doesn't seem to load so, for instance, getting the urls is impossible and always returns "#". But if I remove the .xml portion, everything works as intended.
SO:
template: [Route("foobar")] works
template: [Route("foobar.xml")] doesn't work
What am I missing? Is there any way I can get this to work and keep this in an external controller?
You could use some urlrewrite middleware like below maybe
public class RewriteRules
{
public static void ReWriteRequests(RewriteContext context)
{
var request = context.HttpContext.Request;
if (request.Path.Value.EndsWith("foobar.xml", StringComparison.OrdinalIgnoreCase))
{
context.HttpContext.Request.Path = context.HttpContext.Request.Path.Value.Replace(".xml", "");
}
}
}
Controllers with ".xml" in the route template - Umbraco 14
I'm running into an issue where I'd like to provide XML sitemap using a controller. The sitemap may or may not include paginated results so keeping it dynamically produced within a number of controller endpoints is ideal. While I am trying to use
SimpleMvcSitemp.Core
to handle this, I'm running into one issue.When my route template ends in
.xml
, the data from any documents doesn't seem to load so, for instance, getting the urls is impossible and always returns "#". But if I remove the.xml
portion, everything works as intended.SO:
template:
[Route("foobar")]
workstemplate:
[Route("foobar.xml")]
doesn't workWhat am I missing? Is there any way I can get this to work and keep this in an external controller?
You could use some urlrewrite middleware like below maybe
register in your startup.cs
Thanks Huw,
This was a great idea for a workaround.
My question still stands regarding the necessity of this. Why is this an issue in the first place?
Even so, this is a simple workaround that works well. Thank you!
is working on a reply...