When searching google the only solutions for this come up for MVC websites. My asp.net 4.0 site is not MVC. I want requests for sitemap.xml to load another dynamic .aspx page so I can generate links for google on the fly.
I have spent hours searching, please if you know where I can find the answer, let me know.
I have tried using
RouteTable.Routes.Add("SitemapRoute", new Route("sitemap.xml", new PageRouteHandler("~/sitemap.aspx")))
Your code is correct, and should be placed in the
Application_Start
method inGlobal.asax
. For example:However, you also need to make sure that *.xml files are handled by ASP.NET. By default, *.xml files will just be served up by IIS and not processed by ASP.NET. To make sure they are processed by ASP.NET, you can either:
1) Specify
runAllManagedModulesForAllRequests="true"
on thesystem.webServer
element in yourweb.config
:or 2) add a "Handler Mapping" for .xml files:
I tested this in a sample ASP.NET (non-MVC) project and was able to get the routing to work as you specified.