I\'m working on an ASP.NET MVC app. In this app, I need to dynamically generate the sitemap when its requested. I know how to configure routes in general. However, I\'m not
So you got to do in some steps -
Step 1 - Map the xml extension to take care of by .Net for routing
Add following section in Web.config under <system.webServer>
-
<handlers>
<add name="HtmlFileHandler" path="*.xml" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Step 2 - Define your routes and override requests that match an existing file.
routes.RouteExistingFiles = true;
routes.MapRoute(
name: "Sitemap",
url: "{site}.xml",
defaults: new { controller = "Site", action = "Sitemap", site = UrlParameter.Optional }
);
then step 3 - Try to access /SiteMap.xml
, you will get Controller action hit.