Static File Routes in ASP.NET MVC

前端 未结 1 958
夕颜
夕颜 2021-01-06 08:06

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

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-06 08:42

    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 -

    
      
    
    

    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.

    0 讨论(0)
提交回复
热议问题